Edits history of script submission #23411 for ' Book Meeting on Meeting Link (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Book Meeting on Meeting Link
     * Book a slot on a scheduling page for a contact. `start_time` is ISO 8601 and must be an open slot (see Get Meeting Link Availability); `duration_minutes` must be one of the page's durations. Requires scheduler.meetings.meeting-link.read and write access to the scheduler.
     */
    export async function main(
      auth: RT.Hubspot,
      slug: string,
      first_name: string,
      last_name: string,
      email: string,
      start_time: string,
      duration_minutes: number,
      timezone: string,
      locale: string | undefined,
      guest_emails: string[] | undefined
    ) {
      const url = new URL(
        "https://api.hubapi.com/scheduler/v3/meetings/meeting-links/book"
      )
      url.searchParams.append("timezone", timezone)
    
      const body: { [key: string]: any } = {
        slug,
        firstName: first_name,
        lastName: last_name,
        email,
        startTime: new Date(start_time).getTime(),
        duration: duration_minutes * 60000,
        timezone,
      }
      if (locale != null && locale !== "") body.locale = locale
      if (guest_emails?.length) body.guestEmails = guest_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