0

Create Blog Post

by
Published today

Create a blog post draft.

Script hubspot Verified

The script

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

3
/**
4
 * Create Blog Post
5
 * Create a blog post draft. `body` is a HubSpot blog post object; common fields are name, contentGroupId (the blog ID), slug, blogAuthorId, postBody, metaDescription, htmlTitle. Requires the content scope.
6
 */
7
export async function main(auth: RT.Hubspot, body: { [key: string]: any }) {
8
  const url = new URL(`https://api.hubapi.com/cms/v3/blogs/posts`)
9

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

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26