Get the incident by incident key

Hi, i want to fetch the incident by incident key rather than incident numer or incident ID using api.I followed some discussions regarding date format which will not work in my application because if the incidents are created at the same time and date , at that time, we cannot fetch the particular incident.
I am able to create the incident with giving the incident key in the payload but when i am trying to get that incident with incident key, it is showing “access denied”.

Can anyone help me to do so. Also if there is any idea for fetching the incident with unique parameter rather than incident Id and incident number.

Thanks in advance

I could fetch the incident by incident key giving query params in the base url. With that incident key, can we update the incident status.
Any suggestions on this?

Thanks in Advance

Hi @Nishchitagaddam, you can find an incident with a given incident key using this endpoint:

https://api-reference.pagerduty.com/#!/Incidents/get_incidents

Here is a sample curl request:

curl -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=xxxxxxxxxxxxxxxx' 'https://api.pagerduty.com/incidents?incident_key=sample_key&time_zone=UTC'

Note that if you have alerts enabled, using this filter will still work, as it will search the alert key instead of the incident key.

If there is an incident with this incident/alert key, you should see a response that looks something like this:

{
  "incidents": [
    {
      "incident_number": 834,
     ...
      "id": "P8325WZ",
     ...
    }
  ],
  "limit": 25,
  "offset": 0,
  "total": null,
  "more": false
}

You can use the incident ID in the response (in this case P8325WZ) to update this incident using the Manage incidents endpoint. Here is a sample curl request to acknowledge an incident:

curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'From: example@email.invalid' --header 'Authorization: Token token=xxxxxxxxxxxxxxxx' -d '{
  "incidents": [
    {
      "id": "P8325WZ",
      "type": "incident_reference",
      "status": "acknowledged"
    }
  ]
}' 'https://api.pagerduty.com/incidents'

Note that this endpoint requires a login email of a user on the account to be passed into the request headers. You can also use the PUT Incidents endpoint to accomplish this; the manage incidents endpoint has the advantage of being able to update multiple incidents at once.

I hope that helps!