# Publish BlogPost via API

**URL:** <https://community.hubspot.com/t/publish-blogpost-via-api/76519>\
**Category:** CMS Development\
**Tags:** starter\
**Created:** [March 6, 2023, 8:59am UTC](https://community.hubspot.com/t/publish-blogpost-via-api/76519 "2023-03-06T08:59:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajinvise](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@ajinvise](https://community.hubspot.com/u/ajinvise)\
**Post date:** [March 6, 2023, 8:59am UTC](https://community.hubspot.com/t/publish-blogpost-via-api/76519/1 "2023-03-06T08:59:49Z")

</div>

Have anyone published a blog post from the API? I can create it but it refuses to be published. So I have to go into the portal and publish it manually.  
Here is my code:

```auto
const post = new BlogPost()
// ... filling with content etc
post.currentState = 'PUBLISHED'
post.publishImmediately = true
post.publishDate = new Date

const blogPost = await hubspot.cms.blogs.blogPosts.blogPostsApi.create(post)
await hubspot.cms.blogs.blogPosts.blogPostsApi.pushLive(blogPost.id)

```

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [March 6, 2023, 10:42pm UTC](https://community.hubspot.com/t/publish-blogpost-via-api/76519/2 "2023-03-06T22:42:50Z")

</div>

Hello @ajinvise , Happy Mondat!

Are you using a V3 endpoint? There are a few requirements that this developers document with more details on how to [publish a blog post here.](https://developers.hubspot.com/docs/api/cms/blog-post)

I hope this information helps.

Pam

---

<div class="post-metadata">

**Author:** ![ajinvise](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@ajinvise](https://community.hubspot.com/u/ajinvise)\
**Post date:** [March 7, 2023, 8:15am UTC](https://community.hubspot.com/t/publish-blogpost-via-api/76519/3 "2023-03-07T08:15:09Z")

</div>

Hi @PamCotton !  
Thank you, I am using that exact page to guide me and still fail. So I am using the official client which is using v3. Do you know a developer we can ask to take a look?  
Below is a somewhat more complete example of my code:

```lia-code-sample
 const post = new BlogPost()
 post.contentGroupId = config.BLOG_ID
 post.name = details.Release.Title
 post.slug = details.Release.Title
 post.metaDescription = details.Release.Title
 post.tagIds = tagIds
 post.postBody = details.Release.HtmlBody.replace(
 /(<[^>]*) style=("[^"]+"|'[^']+')([^>]*>)/gi,
 '$1$3'
 );
 post.postSummary
 post.featuredImage = details.Release.Images[0].DownloadUrl
 post.blogAuthorId = config.BLOG_AUTHOR_ID
 post.currentState = 'PUBLISHED'
 post.publishImmediately = true
 post.publishDate = new Date

 post.widgets = {
 post_settings: {
 press_data: {
 ...trimmedDetails,
 }
 }
 }
 // Successful
 const blogPost = await hubspot.cms.blogs.blogPosts.blogPostsApi.create(post)

 // Successful but the post is not published
 // It is weird because it can be publish via portal no problem.
 await hubspot.cms.blogs.blogPosts.blogPostsApi.pushLive(blogPost.id)

```

---

<div class="post-metadata">

**Author:** ![Stegemann](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Stegemann](https://community.hubspot.com/u/Stegemann)\
**Post date:** [March 20, 2023, 9:31pm UTC](https://community.hubspot.com/t/publish-blogpost-via-api/76519/4 "2023-03-20T21:31:59Z")

</div>

Hi!

I had the exact same issue. For me it was the property state that did the trick. When I passed State: ‘PUBLISHED’ it worked. Did not use the pushLive function.

/Mats
