Reputation: 795
I would like to retrieve all PagerDuty incidents that have occurred on a specific day via the API. I am using the following GET request:
curl -i -H "Content-type: application/json" \
-H "Authorization: Token token=wouldntyouliketoknow" \
-X GET \
--data-urlencode "since=2016-05-03T00:00Z" \
--data-urlencode "until=2016-05-03T23:59Z" \
--data-urlencode "offset=100" \
"https://my.pagerduty.com/api/v1/incidents"
There is just one issue with the data that is returned. The timestamps of the returned incidents indicate that the incidents are for different dates, just not the one I specified in the since
and until
parameters. I checked via the UI that there are more than 100 incidents for the specified date.
How should I modify my query to return all incidents for the specified date?
Upvotes: 2
Views: 3374
Reputation: 56
The time you are specifying is in UTC. My guess is you are in another timezone, which is making the results look incorrect.
The dates are specified in the ISO 8601 format (as per PagerDuty's Developer documentation), so you could specify the date and time with timezone (assuming UTC-7) like so:
2016-05-03T23:59-07
If you are in, say UTC+3, you'd use:
2016-05-03T23:59+03
PagerDuty's API returns at most 100 records, but varies per endpoint, so you'll need to increment the offset parameter and make an API call per page.
For the first 100:
curl -i -H "Content-type: application/json" \
-H "Authorization: Token token=wouldntyouliketoknow" \
-X GET \
--data-urlencode "since=2016-05-03T00:00Z" \
--data-urlencode "until=2016-05-03T23:59Z" \
--data-urlencode "limit=100" \
"https://my.pagerduty.com/api/v1/incidents"
For the second 100:
curl -i -H "Content-type: application/json" \
-H "Authorization: Token token=wouldntyouliketoknow" \
-X GET \
--data-urlencode "since=2016-05-03T00:00Z" \
--data-urlencode "until=2016-05-03T23:59Z" \
--data-urlencode "limit=100" \
--data-urlencode "offset=100" \
"https://my.pagerduty.com/api/v1/incidents"
Cheers!
Upvotes: 4