0

List Teams

by
Published 4 days ago

List teams in the account, optionally filtered by a search query.

Script pagerduty Verified

The script

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

3
/**
4
 * List Teams
5
 * List teams in the account, optionally filtered by a search query.
6
 */
7
export async function main(
8
  auth: RT.Pagerduty,
9
  query: string | undefined,
10
  limit: number | undefined,
11
  offset: number | undefined,
12
) {
13
  const url = new URL("https://api.pagerduty.com/teams")
14
  if (query !== undefined && query !== "") url.searchParams.append("query", query)
15
  if (limit !== undefined) url.searchParams.append("limit", String(limit))
16
  if (offset !== undefined) url.searchParams.append("offset", String(offset))
17

18
  const response = await fetch(url, {
19
    method: "GET",
20
    headers: {
21
      Authorization: `Token token=${auth.token}`,
22
      Accept: "application/vnd.pagerduty+json;version=2",
23
    },
24
  })
25

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

30
  return await response.json()
31
}
32