0

List Services

by
Published 4 days ago

List services (systems/apps that generate incidents), optionally filtered by a search query or team IDs.

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