1 | |
2 |
|
3 | |
4 | * List Escalation Policies |
5 | * List escalation policies, optionally filtered by a search query, team IDs, or user IDs. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Pagerduty, |
9 | query: string | undefined, |
10 | team_ids: string[] | undefined, |
11 | user_ids: string[] | undefined, |
12 | limit: number | undefined, |
13 | offset: number | undefined, |
14 | ) { |
15 | const url = new URL("https://api.pagerduty.com/escalation_policies") |
16 | if (query !== undefined && query !== "") url.searchParams.append("query", query) |
17 | if (team_ids) for (const t of team_ids) url.searchParams.append("team_ids[]", t) |
18 | if (user_ids) for (const u of user_ids) url.searchParams.append("user_ids[]", u) |
19 | if (limit !== undefined) url.searchParams.append("limit", String(limit)) |
20 | if (offset !== undefined) url.searchParams.append("offset", String(offset)) |
21 |
|
22 | const response = await fetch(url, { |
23 | method: "GET", |
24 | headers: { |
25 | Authorization: `Token token=${auth.token}`, |
26 | Accept: "application/vnd.pagerduty+json;version=2", |
27 | }, |
28 | }) |
29 |
|
30 | if (!response.ok) { |
31 | throw new Error(`${response.status} ${await response.text()}`) |
32 | } |
33 |
|
34 | return await response.json() |
35 | } |
36 |
|