0

List On-Calls

by
Published 4 days ago

List on-call entries — who is on call now or during a time window — filterable by schedule IDs, escalation policy IDs, and user IDs. Time params use ISO 8601 with an explicit UTC offset; the range cannot exceed 3 months.

Script pagerduty Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * List On-Calls
5
 * List on-call entries — who is on call now or during a time window — filterable by schedule IDs, escalation policy IDs, and user IDs. Time params use ISO 8601 with an explicit UTC offset; the range cannot exceed 3 months.
6
 */
7
export async function main(
8
  auth: RT.Pagerduty,
9
  schedule_ids: string[] | undefined,
10
  escalation_policy_ids: string[] | undefined,
11
  user_ids: string[] | undefined,
12
  since: string | undefined,
13
  until: string | undefined,
14
  earliest: boolean | undefined,
15
  limit: number | undefined,
16
  offset: number | undefined,
17
) {
18
  const url = new URL("https://api.pagerduty.com/oncalls")
19
  if (schedule_ids)
20
    for (const s of schedule_ids) url.searchParams.append("schedule_ids[]", s)
21
  if (escalation_policy_ids)
22
    for (const e of escalation_policy_ids)
23
      url.searchParams.append("escalation_policy_ids[]", e)
24
  if (user_ids) for (const u of user_ids) url.searchParams.append("user_ids[]", u)
25
  if (since !== undefined && since !== "") url.searchParams.append("since", since)
26
  if (until !== undefined && until !== "") url.searchParams.append("until", until)
27
  if (earliest !== undefined)
28
    url.searchParams.append("earliest", String(earliest))
29
  if (limit !== undefined) url.searchParams.append("limit", String(limit))
30
  if (offset !== undefined) url.searchParams.append("offset", String(offset))
31

32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: `Token token=${auth.token}`,
36
      Accept: "application/vnd.pagerduty+json;version=2",
37
    },
38
  })
39

40
  if (!response.ok) {
41
    throw new Error(`${response.status} ${await response.text()}`)
42
  }
43

44
  return await response.json()
45
}
46