REST - List schedules for a user

Trying to list all schedules where a user is assigned. Thoughts?

https://developer.pagerduty.com/api-reference/reference/REST/openapiv3.json/paths/~1oncalls/get

This doesn’t enumerate the users that are in the schedule, rather, it shows who is on-call or all of the historical on-calls.

All I want to do is return a list of schedules based on a user ID. I was thinking that this would work, but it doesn’t

https://api.pagerduty.com/schedules?query='user id’

Hi Jody!

There isn’t a way to capture the schedules a user is on via the https://api.pagerduty.com/schedules/?query=<user id> URL. The query option is best for searching the schedule names.

The on-calls endpoint would be the best option to return a list of schedules a user is on over a period of time. Alternatively, you could list all schedules with the users and then create a secondary filter/query system which searches the results with the provided user ID however this is not directly supported with our REST API query options.

Thanks. I chose to get all of the schedules and then query the users in each (by ID). The only issues with this, is that the user list includes ALL users (unable to filter out old entries). Still trying to deal with that.

Thanks

Hi Jody,

The list of users stored in the schedule does retain a list of previous users on-call in it.

You could as a since parameter to gather the list of users from such as https://api.pagerduty.com/schedules/ID?time_zone=UTC&since=2021-02-09'.

This limits the user list to just the users upcoming in the schedule.

1 Like

Hey Team,

Is there still no way to pull schedules for a specific user? I’m looking to see if a user has an on call schedule equal to TRUE for auditing purposes.

Thanks in advance.

Hi Jay. There isn’t a way to associate a user with a particular schedule in that direction.

You can pull escalation policies per-user, and get the schedules from there. That endpoint would be https://api.pagerduty.com/escalation_policies?user_ids[]=USERID".

That will also let you know if the user is included in an escalation policy directly and not just as part of a schedule. They’ll be included in the JSON a couple layers down, under escalation_rules.targets.