Edits history of script submission #23415 for ' Create Blog Post (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Blog Post
     * 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.
     */
    export async function main(auth: RT.Hubspot, body: { [key: string]: any }) {
      const url = new URL(`https://api.hubapi.com/cms/v3/blogs/posts`)
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify(body),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago