Get resolved incidents from spesific service

rest-api
questions
incidents

(Eli Fish) #1

Hi,
I am trying to get all incident that relevant to specific service but looks like the API isn’t take only the service that i am writing to him.
This is the code in python:

def get_incidents_list():
url = "https://mycompany.pagerduty.com/api/v1/incidents"
headers = {
‘Authorization’: ‘Token token=Uw5pPF2zwfCy4DZWzgqv’
}

payload = {‘status’: ‘triggered,resolved’, ‘service’: ‘P0ITW5R’, ‘since’: SINCEDATE + ‘T’ + SINCETIME + ‘Z’}
res = requests.get(url, headers=headers, data=payload)
son_res = res.json()
print “"
print json.dumps(son_res)
print "

I am getting all kind of incident that not belong to the service that i want.


(Alex Maier) #2

Do you know which other services are addressing the events API? If you do, and it’s something that nobody else in your company is using, you can probably create a custom rule to auto-resolve the incidents from services that you don’t want to be alerted about. Or you can remove the integration with the services that you don’t want writing to the API. But again, check that nobody is using those first.


(Sean Higgins) #3

Hi Eli,

Looks like you’re trying to send your query parameters in the payload of the GET request. Instead, you should add the filters (status, service, etc.) into the URL you are hitting.

The URL you would want to perform the GET request against would be:
https://api.pagerduty.com/incidents?since=SINCEDATE&statuses%5B%5D=triggered&statuses%5B%5D=resolved&service_ids%5B%5D=P0ITW5R&time_zone=UTC

Here’s a quick snippet from our API docs around sending body parameters:

Query parameters located in query should be specified in the query string when making a request. Body parameters located in body should be specified in JSON format within the request body. Body parameters are typically only used with POST and PUT endpoints. Header parameters located in header should be specified as standard HTTP headers in the header section of the request.

The interactive API docs for our incidents API might be a quick and easy way to test out your query. You can find the specific page here.

Hope that helps.

Sean


(system) #4