0

List Pipelines and Stages

by
Published today

List the pipelines of an object type (deals, tickets, or another pipeline-enabled object) with their stages.

Script hubspot Verified

The script

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

3
/**
4
 * List Pipelines and Stages
5
 * List the pipelines of an object type (deals, tickets, or another pipeline-enabled object) with their stages. Stage and pipeline IDs are what `dealstage`, `pipeline`, `hs_pipeline` and `hs_pipeline_stage` expect. Pipelines other than deals need that object's scope (e.g. tickets).
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  object_type:
10
    | "deals"
11
    | "tickets"
12
    | "leads"
13
    | "orders"
14
    | "appointments"
15
    | "courses"
16
    | "listings"
17
    | "services"
18
) {
19
  const url = new URL(`https://api.hubapi.com/crm/v3/pipelines/${object_type}`)
20

21
  const response = await fetch(url, {
22
    headers: {
23
      Authorization: `Bearer ${auth.token}`,
24
      Accept: "application/json",
25
    },
26
  })
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  return await response.json()
33
}
34