Edits history of script submission #23476 for ' Update Blog Post (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Update Blog Post
     * Update a blog post directly. On a published post this changes the live version immediately; use Update Blog Post Draft to stage changes instead. Requires the content scope.
     */
    export async function main(
      auth: RT.Hubspot,
      blog_post_id: string,
      body: { [key: string]: any }
    ) {
      const url = new URL(
        `https://api.hubapi.com/cms/v3/blogs/posts/${blog_post_id}`
      )
    
      const response = await fetch(url, {
        method: "PATCH",
        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