Filtering Fields on the v2 API


(Jose Perez) #1

I’m trying to make some changes to a script that curls the old API so it can use the new API. The script filters the fields for incident_number and ID. I’ve looked up the documentation and can’t seem to find the docs that will let get those two things as I only end up getting all the things. Below is an example of the two curl commands. I’ve tried a few things as stated in the docs but haven’t had much luck.

Curl Using the Old API
curl -X GET --header ‘Accept: application/json’ --header ‘Authorization: Token token=SuperSecretTOKEN’ ‘,id

Curl Using the New API
curl -X GET --header ‘Accept: application/vnd.pagerduty+json;version=2’ --header ‘Authorization: Token token=SuperSecretTOKEN’ ‘

(Jay Chiarella) #2

Hi Jose,

Thanks for the details.

You’d just need to append /{incident_id} to the new API endpoint. So the curl command should be:

curl -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=SuperSecretTOKEN' '{id}'

You can read further about this endpoint on our documentation here:!/Incidents/get_incidents_id



(Jose Perez) #3

Hey Jay

Thanks for getting back to me. Unfortunately gets me more info than I really need at them moment. What I’m looking for is more of a filter so I only get the incident_numbers and ids much like the old curl command used to let me do. Any ideas on how to achieve that?

Thanks again for the help.

(Karynn Ikeda) #5


The API v2 does not support filtering to only return specific fields like incident id and number (see a list of available incident filters), but I was able to filter down to just incident id and number using JQ to process the response:

curl -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=SuperSecretTOKEN' '' | jq '{incidents: [.incidents[] | {incident_number: .incident_number, id: .id}]}

(system) #6