1 | |
2 |
|
3 | |
4 | * List Sequence States |
5 | * Lists sequence states (prospect ↔ sequence memberships), filterable by prospect, sequence or state. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Outreach, |
9 | filter_prospect_id: number | undefined, |
10 | filter_sequence_id: number | undefined, |
11 | filter_state: string | undefined, |
12 | page_size: number | undefined, |
13 | page_after: string | undefined |
14 | ) { |
15 | const url = new URL("https://api.outreach.io/api/v2/sequenceStates") |
16 | if (filter_prospect_id !== undefined) { |
17 | url.searchParams.append("filter[prospect][id]", String(filter_prospect_id)) |
18 | } |
19 | if (filter_sequence_id !== undefined) { |
20 | url.searchParams.append("filter[sequence][id]", String(filter_sequence_id)) |
21 | } |
22 | if (filter_state !== undefined && filter_state !== "") { |
23 | url.searchParams.append("filter[state]", filter_state) |
24 | } |
25 | if (page_size !== undefined) { |
26 | url.searchParams.append("page[size]", String(page_size)) |
27 | } |
28 | if (page_after !== undefined && page_after !== "") { |
29 | url.searchParams.append("page[after]", page_after) |
30 | } |
31 |
|
32 | const response = await fetch(url, { |
33 | headers: { |
34 | Authorization: `Bearer ${auth.token}`, |
35 | Accept: "application/vnd.api+json", |
36 | }, |
37 | }) |
38 |
|
39 | if (!response.ok) { |
40 | throw new Error(`${response.status} ${await response.text()}`) |
41 | } |
42 |
|
43 | return await response.json() |
44 | } |
45 |
|