Edits history of script submission #23420 for ' Create Marketing Email (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Marketing Email
     * Create a marketing email draft. `body` is a HubSpot marketing email object; the minimum is {"name": "..."} and common fields are subject, templatePath, from {fromName, replyTo}, to {contactLists}, content. Requires the content scope.
     */
    export async function main(auth: RT.Hubspot, body: { [key: string]: any }) {
      const url = new URL(`https://api.hubapi.com/marketing/v3/emails`)
    
      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