0

Add Note to Incident

by
Published 4 days ago

Add a text note to an incident's timeline — useful for documenting investigation steps or handoff context. Requires the resource's from_email when the API key is account-scoped.

Script pagerduty
  • Submitted by hugo989 Typescript (fetch-only)
    Created 5 days ago
    1
    //native
    2
    
    
    3
    /**
    4
     * Add Note to Incident
    5
     * Add a text note to an incident's timeline — useful for documenting investigation steps or handoff context. Requires the resource's from_email when the API key is account-scoped.
    6
     */
    7
    export async function main(
    8
      auth: RT.Pagerduty,
    9
      incident_id: string,
    10
      content: string,
    11
    ) {
    12
      const headers: { [key: string]: string } = {
    13
        Authorization: `Token token=${auth.token}`,
    14
        "Content-Type": "application/json",
    15
        Accept: "application/vnd.pagerduty+json;version=2",
    16
      }
    17
      if (auth.from_email) headers["From"] = auth.from_email
    18
    
    
    19
      const response = await fetch(
    20
        `https://api.pagerduty.com/incidents/${incident_id}/notes`,
    21
        {
    22
          method: "POST",
    23
          headers,
    24
          body: JSON.stringify({ note: { content } }),
    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