Edits history of script submission #23467 for ' List Threads (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Threads
     * List conversation threads, optionally for one inbox or one contact. `associated_contact_id` cannot be combined with `inbox_id`. Requires conversations.read.
     */
    export async function main(
      auth: RT.Hubspot,
      inbox_id: string | undefined,
      associated_contact_id: string | undefined,
      thread_status: "OPEN" | "CLOSED" | undefined,
      sort: string | undefined,
      limit: number | undefined,
      after: string | undefined,
      archived: boolean | undefined
    ) {
      const url = new URL(
        `https://api.hubapi.com/conversations/v3/conversations/threads`
      )
      if (inbox_id != null && inbox_id !== "")
        url.searchParams.append("inboxId", inbox_id)
      if (associated_contact_id != null && associated_contact_id !== "")
        url.searchParams.append("associatedContactId", associated_contact_id)
      if (thread_status != null && thread_status !== "")
        url.searchParams.append("threadStatus", thread_status)
      if (sort != null && sort !== "") url.searchParams.append("sort", sort)
      if (limit != null) url.searchParams.append("limit", String(limit))
      if (after != null && after !== "") url.searchParams.append("after", after)
      if (archived) url.searchParams.append("archived", String(archived))
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 4 hours ago