Edits history of script submission #23419 for ' Create Form (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Form
     * Create a marketing form. `body` is a HubSpot form definition; the minimum is {"formType": "hubspot", "name": "...", "createdAt": "<ISO date>", "fieldGroups": [], "configuration": {}, "displayOptions": {}, "legalConsentOptions": {"type": "none"}}. Requires the forms scope.
     */
    export async function main(auth: RT.Hubspot, body: { [key: string]: any }) {
      const url = new URL(`https://api.hubapi.com/marketing/v3/forms`)
    
      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 4 hours ago