Pull the monthly schedule via the api?


(Jakub Jakubik) #1

Hi,

I’m trying to automate a monthly report on who was oncall.

I’ve tried the /schedule/{id} api but I don’t seem to be getting the data I need.
I’d expect an output of start-end-user_id for a given rotation - something I see via the web.
It would just be the base layer, I’m not interested in the override one (for now).

It seems that I’d need to calculate this myself based on what the api gives me? Or is there a way to pull this directly? I’m interested in the historical data, not the future one.

thanks!


(Jay Chiarella) #2

Hi Jakub,

The best way to pull schedule data from the REST API is the /schedules/{id} endpoint that you were using.

I recommend to check out our developer documentation on this endpoint and selecting the “Show samples” button at the top right of the page. This will show you a response sample and the response schema as well.

In the response schema, you can view that the ScheduleLayer object has as a start and end properties that you can parse for each specific rotation within the schedule.

Let me know if this helps!

Jay


(Jakub Jakubik) #3

hi Jay,

I’ve checked that, and all I get is when the schedule starts and who the members are,
from what I understand I’d actually have to calculate the rotation and dates for every member.
I’d like to get
{'Alice', '01-01-2001', '01-02-2001'},{'Bob', '01-02-2001', '01-03-2001'},{'Alice', '01-04-2001','01-05-2001'}
or something along these lines


(Jay Chiarella) #4

Hi Jakub,

If you include the since or until parameters in your API request, then the API response will contain a rendered_schedule_entries array which contains the “start” time, the “end” time , and the “user”. The rendered_schedule_entries array will be in the schedule_layers property.

The schedule_layers property in the API response is the data from each layer in the schedule.

Note that the above shows each individual shift, and it does not accumulate the amount of time a user has been on-call for a specific time period.

Perhaps you should take a look at our /oncalls endpoint, which allows you to list the on-call entries during a given time range, where you can filter the API response by adding a user id, escalation policy id, or a schedule id in the parameter of the API request.

Hope this helps!

Jay


(Jakub Jakubik) #5

hi Jay,

the problem is that in the return I get

"rendered_schedule_entries":[]

the rest of the fields seem to be there - layer name etc

Even if I try the api samples - using the default key and schedule id P538IZH - the rest is there, but not the rendered_schedule_entries…

am I missing something?


(Jay Chiarella) #6

Hi Jakub,

Can you please confirm if you include the since and until parameters in your API request?

If you did, then we’ll need more information from your specific account. Would you be able to drop a note to support@pagerduty.com, referencing this community post along with some details about the API request where you received an empty array for "rendered_schedule_entries":[] :

  • A timestamp (including timezone)
  • The URL of the API request
  • The last 4 tokens of the REST API key used.

Thanks,

Jay


(Jakub Jakubik) #7

I had an issue with passing the ‘since’ and ‘until’ get params. It’s all working now. Thanks a lot!


(Simon Fiddaman) #8

+1 for using /oncalls - we also use this for our oncall Slackbot.


(system) #9