0

Push Blog Post Draft Live

by
Published today

Publish the draft version of a blog post, replacing the live version.

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Push Blog Post Draft Live
5
 * Publish the draft version of a blog post, replacing the live version. Requires the content scope.
6
 */
7
export async function main(auth: RT.Hubspot, blog_post_id: string) {
8
  const url = new URL(
9
    `https://api.hubapi.com/cms/v3/blogs/posts/${blog_post_id}/draft/push-live`
10
  )
11

12
  const response = await fetch(url, {
13
    method: "POST",
14
    headers: {
15
      Authorization: `Bearer ${auth.token}`,
16
      Accept: "application/json",
17
    },
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23
  if (response.status === 204) return { success: true }
24

25
  return await response.json()
26
}
27