0

Update Blog Post Draft

by
Published today

Update the draft version of a blog post without touching the live version.

Script hubspot Verified

The script

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

3
/**
4
 * Update Blog Post Draft
5
 * Update the draft version of a blog post without touching the live version. Publish it with Push Blog Post Draft Live. Requires the content scope.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  blog_post_id: string,
10
  body: { [key: string]: any }
11
) {
12
  const url = new URL(
13
    `https://api.hubapi.com/cms/v3/blogs/posts/${blog_post_id}/draft`
14
  )
15

16
  const response = await fetch(url, {
17
    method: "PATCH",
18
    headers: {
19
      Authorization: `Bearer ${auth.token}`,
20
      "Content-Type": "application/json",
21
      Accept: "application/json",
22
    },
23
    body: JSON.stringify(body),
24
  })
25

26
  if (!response.ok) {
27
    throw new Error(`${response.status} ${await response.text()}`)
28
  }
29

30
  return await response.json()
31
}
32