API Endpoint that provides start/end time for rotation
Asked by jsimon:

I am working to create a custom 'Who's On-call' widget for opsgenie similar to this: <https://demo.pagerbeauty.sergii.org/v1/schedules/PDUQGYJ.html> - Specifically I'm stuck creating the 'From' and 'To' fields indicating how long they are on-call for.

I am struggling to find an API endpoint that will give me the start and end time of a given rotation for a specific user that is currently on-call. The rotations endpoint looks to only provide the start and end time of the entire rotation.

Is there an API endpoint that can provide the start time and end time of the current rotation for a specific user?

![Screenshot 2023-12-14 165720.png](/t5/image/serverpage/image-id/296924i4BDF05A515260A21/image-size/large?v=v2&px=999 "Screenshot 2023-12-14 165720.png")


Answers:
author: jsimon
body: For posterity, [Get Schedule Timeline](https://docs.opsgenie.com/docs/schedule-api#get-schedule-timeline) has the start and end time of a user on a rotation.


author: Rafael Meira
body: Hey [@jsimon](/t5/user/viewprofilepage/user-id/5382555)   

The Opsgenie API doesn't provide a direct endpoint to get the start and end time of the current rotation for a specific user.   

You could use the combination of "Get Schedule" (\`GET /v2/schedules/{identifier}\`) and "Get On-Call" (\`GET /v2/schedules/{identifier}/on-calls\`) APIs to achieve this.   

Get the schedule details, iterate over the rotations to find the specific user, then use "Get On-Call" API to get the start and end time of that user's on-call period.  

Let me know if you have any questions or face any issues.  
Also, in case you need further assistance, I would recommend you open a formal ticket with our support here: <https://support.atlassian.com/opsgenie/>   

<br />

Best,  
Rafa

comments: author: jsimon
body: Thanks Rafa.

Not sure if I am misunderstanding your explanation or you misunderstood my question.

*"Get the schedule details, iterate over the rotations to find the specific user, then use "Get On-Call" API to get the start and end time of that user's on-call period."*

I am not clear how this will work as the "Get On-Call" API does not return anything about the time for that user's shift (though I think it should) and the Get Schedule" API only returns the start and end data of the rotation as a whole - which is less than useful

I suppose it's possible to extrapolate the start and end times based on the "timeRestriction" fields that are returned from the "Get-Schedule" API, but I would argue that this should be done on the API side and be returned with the "Get-Oncall" API.

Regardless, I've opened a support ticket to look into this further.

Thanks for the help.


author: Rafael Meira
body: [@jsimon](/t5/user/viewprofilepage/user-id/5382555)   

You're correct that the "Get Schedule" API only provides the start and end times for the entire rotation, and the "Get On-Call" API doesn't offer specific start and end times for a user's shift.

Your point about extrapolating the times based on the "timeRestriction" fields is valid, but as you've noted, it would require additional calculations on your end. It's a viable workaround for now, although not as straightforward as having the API provide the data directly.

We appreciate the feedback about enhancing the "Get On-Call" API to include this feature. We strive to improve our services based on user feedback and your input is valuable to us. I will create a Feature Request on this topic.

I'm glad to hear you've opened a support ticket.   

Best,


Tags: cloud