Pull the current on-call user from API

I am trying to pull the exact user who is on-call at the given time of the API request.

I’ve had a look through the documentation and can only see a way to list all of the on-call users , or list all users from a schedule - But i can’t seem to find a way to extract from this who is currently on call right now.

Does anyone know a way to pull this using python?

Hi Kris!

You can get the responder who’s on-call right now using the earliest=true query parameter.

curl --request GET 'https://api.pagerduty.com/oncalls?include[]=users&schedule_ids[]=XXXXXXX&earliest=true' \
--header 'Authorization: Token token=YOUR_API_KEY' \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header 'Content-Type: application/json'

The query above will filter by schedule_ids[]=XXXXXXX, but you can instead filter by schedule_ids[] or user_ids[] as well. These 3 query parameters will work with either a single string or an array of them separated by commas.

I hope this helps!

Luke S.
Technical Support Specialist
PagerDuty Support Team

def Get_Current_OnCall_User_Name(schedule_id):
        today = date.today()
        since = str(today) + " 08:00:00"
        until = str(today) + " 20:00:00"
        timezone = "America/Los_Angeles"
            oncall = self.pd_session.rget('/schedules/{}'.format(schedule_id), params={'time_zone': timezone,'since': since, 'until': until})
            return oncall["final_schedule"]["rendered_schedule_entries"][0]["user"]["summary"]
        except Exception as e:
            return None