0

Search Lists

by
Published today

Search the account's lists (segments) by name.

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Search Lists
5
 * Search the account's lists (segments) by name. Paginate with `offset`. Requires crm.lists.read.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  query: string | undefined,
10
  processing_types: ("MANUAL" | "DYNAMIC" | "SNAPSHOT")[] | undefined,
11
  count: number | undefined,
12
  offset: number | undefined
13
) {
14
  const url = new URL(`https://api.hubapi.com/crm/v3/lists/search`)
15

16
  const body: { [key: string]: any } = {}
17
  if (query != null && query !== "") body.query = query
18
  if (processing_types?.length) body.processingTypes = processing_types
19
  if (count != null) body.count = count
20
  if (offset != null) body.offset = offset
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      Authorization: `Bearer ${auth.token}`,
26
      "Content-Type": "application/json",
27
      Accept: "application/json",
28
    },
29
    body: JSON.stringify(body),
30
  })
31

32
  if (!response.ok) {
33
    throw new Error(`${response.status} ${await response.text()}`)
34
  }
35

36
  return await response.json()
37
}
38