0

Create Schedule Override

by
Published 4 days ago

Override an on-call schedule to put a specific user on call for a time window. Start and end use ISO 8601 with an explicit UTC offset (e.g. 2026-06-02T08:00:00-07:00) — always include the offset so the window lands in the right slot.

Script pagerduty Verified

The script

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

3
/**
4
 * Create Schedule Override
5
 * Override an on-call schedule to put a specific user on call for a time window. Start and end use ISO 8601 with an explicit UTC offset (e.g. 2026-06-02T08:00:00-07:00) — always include the offset so the window lands in the right slot.
6
 */
7
export async function main(
8
  auth: RT.Pagerduty,
9
  schedule_id: string,
10
  user_id: string,
11
  start: string,
12
  end: string,
13
) {
14
  const response = await fetch(
15
    `https://api.pagerduty.com/schedules/${schedule_id}/overrides`,
16
    {
17
      method: "POST",
18
      headers: {
19
        Authorization: `Token token=${auth.token}`,
20
        "Content-Type": "application/json",
21
        Accept: "application/vnd.pagerduty+json;version=2",
22
      },
23
      body: JSON.stringify({
24
        overrides: [
25
          { start, end, user: { id: user_id, type: "user_reference" } },
26
        ],
27
      }),
28
    },
29
  )
30

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

35
  return await response.json()
36
}
37