Edits history of script submission #22611 for ' Add Note to Incident (pagerduty)'

  • bunnative
    //native
    
    /**
     * Add Note to Incident
     * 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.
     */
    export async function main(
      auth: RT.Pagerduty,
      incident_id: string,
      content: string,
    ) {
      const headers: { [key: string]: string } = {
        Authorization: `Token token=${auth.token}`,
        "Content-Type": "application/json",
        Accept: "application/vnd.pagerduty+json;version=2",
      }
      if (auth.from_email) headers["From"] = auth.from_email
    
      const response = await fetch(
        `https://api.pagerduty.com/incidents/${incident_id}/notes`,
        {
          method: "POST",
          headers,
          body: JSON.stringify({ note: { content } }),
        },
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 days ago