Edits history of script submission #23473 for ' Search Lists (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Search Lists
     * Search the account's lists (segments) by name. Paginate with `offset`. Requires crm.lists.read.
     */
    export async function main(
      auth: RT.Hubspot,
      query: string | undefined,
      processing_types: ("MANUAL" | "DYNAMIC" | "SNAPSHOT")[] | undefined,
      count: number | undefined,
      offset: number | undefined
    ) {
      const url = new URL(`https://api.hubapi.com/crm/v3/lists/search`)
    
      const body: { [key: string]: any } = {}
      if (query != null && query !== "") body.query = query
      if (processing_types?.length) body.processingTypes = processing_types
      if (count != null) body.count = count
      if (offset != null) body.offset = offset
    
      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