0

Resolve Event (Events API v2)

by
Published 4 days ago

Resolve an alert previously triggered via the Events API v2, identified by its dedup_key. Resolving closes the corresponding incident if no other alerts keep it open.

Script pagerduty
  • Submitted by hugo989 Typescript (fetch-only)
    Created 5 days ago
    1
    //native
    2
    
    
    3
    /**
    4
     * Resolve Event (Events API v2)
    5
     * Resolve an alert previously triggered via the Events API v2, identified by its dedup_key. Resolving closes the corresponding incident if no other alerts keep it open.
    6
     */
    7
    export async function main(auth: RT.PagerdutyEvents, dedup_key: string) {
    8
      const response = await fetch("https://events.pagerduty.com/v2/enqueue", {
    9
        method: "POST",
    10
        headers: {
    11
          "Content-Type": "application/json",
    12
          Accept: "application/json",
    13
        },
    14
        body: JSON.stringify({
    15
          routing_key: auth.routing_key,
    16
          event_action: "resolve",
    17
          dedup_key,
    18
        }),
    19
      })
    20
    
    
    21
      if (!response.ok) {
    22
        throw new Error(`${response.status} ${await response.text()}`)
    23
      }
    24
    
    
    25
      return await response.json()
    26
    }
    27