Edits history of script submission #23424 for ' Create Page (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Page
     * Create a website page or landing page draft. `body` is a HubSpot page object; common fields are name, templatePath, slug, htmlTitle, metaDescription, domain, layoutSections. Requires the content scope.
     */
    export async function main(
      auth: RT.Hubspot,
      page_type: "site-pages" | "landing-pages",
      body: { [key: string]: any }
    ) {
      const url = new URL(`https://api.hubapi.com/cms/v3/pages/${page_type}`)
    
      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