Edits history of script submission #23470 for ' Push Blog Post Draft Live (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Push Blog Post Draft Live
     * Publish the draft version of a blog post, replacing the live version. Requires the content scope.
     */
    export async function main(auth: RT.Hubspot, blog_post_id: string) {
      const url = new URL(
        `https://api.hubapi.com/cms/v3/blogs/posts/${blog_post_id}/draft/push-live`
      )
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
      if (response.status === 204) return { success: true }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago