0

List Priorities

by
Published 4 days ago

List the account's incident priorities (e.g. P1–P5). Priorities are an account feature; an empty list means the feature is not enabled. Use the returned IDs as priority_id when creating or updating incidents.

Script pagerduty
  • Submitted by hugo989 Typescript (fetch-only)
    Created 5 days ago
    1
    //native
    2
    
    
    3
    /**
    4
     * List Priorities
    5
     * List the account's incident priorities (e.g. P1–P5). Priorities are an account feature; an empty list means the feature is not enabled. Use the returned IDs as priority_id when creating or updating incidents.
    6
     */
    7
    export async function main(
    8
      auth: RT.Pagerduty,
    9
      limit: number | undefined,
    10
      offset: number | undefined,
    11
    ) {
    12
      const url = new URL("https://api.pagerduty.com/priorities")
    13
      if (limit !== undefined) url.searchParams.append("limit", String(limit))
    14
      if (offset !== undefined) url.searchParams.append("offset", String(offset))
    15
    
    
    16
      const response = await fetch(url, {
    17
        method: "GET",
    18
        headers: {
    19
          Authorization: `Token token=${auth.token}`,
    20
          Accept: "application/vnd.pagerduty+json;version=2",
    21
        },
    22
      })
    23
    
    
    24
      if (!response.ok) {
    25
        throw new Error(`${response.status} ${await response.text()}`)
    26
      }
    27
    
    
    28
      return await response.json()
    29
    }
    30