0

Schedule Blog Post

by
Published today

Schedule a blog post to be published at a given time (ISO 8601).

Script hubspot Verified

The script

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

3
/**
4
 * Schedule Blog Post
5
 * Schedule a blog post to be published at a given time (ISO 8601). Requires the content scope.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  blog_post_id: string,
10
  publish_date: string
11
) {
12
  const url = new URL(`https://api.hubapi.com/cms/v3/blogs/posts/schedule`)
13

14
  const body: { [key: string]: any } = {}
15
  body.id = blog_post_id
16
  body.publishDate = publish_date
17

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

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31
  if (response.status === 204) return { success: true }
32

33
  return await response.json()
34
}
35