Remove user over API
Asked by Mikhail:

When I try to delete a user through the API, I get an error like:  
**Please remove it from schedules: \[My Test Schedule\]'**

how can I delete a user from the schedule through the API?

p. s. I am trying to automate the issuance of access, the user may have many schedules  

Earlier, he also wrote that you need to remove a user from the team, but it was not difficult here, I easily found a way in the documentation <https://docs.opsgenie.com/docs/team-member-api#remove-team-member>


Answers:
author: Nick H
body: Hi [@Mikhail](/t5/user/viewprofilepage/user-id/4178181) ,

You can find the user's schedules by first running a GET to list all users, and grab the user's ID that needs to be removed from any schedules: <https://docs.opsgenie.com/docs/user-api#list-user>

![sched API comm 5.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/120260iBD11D0ECC8CE6911/image-size/large?v=v2&px=999 "sched API comm 5.jpg")

Then list the user's schedules using this API call: <https://docs.opsgenie.com/docs/user-api#list-user-schedules>

![sched API comm 1.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/120255iE50D3254DAE9C449/image-size/large?v=v2&px=999 "sched API comm 1.jpg")

From here, you'd have to run a GET on the schedules to show what rotation(s) the user is a participant in: <https://docs.opsgenie.com/docs/schedule-api#get-schedule>

![sched API comm 2.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/120257iFDCF5543C119554D/image-size/large?v=v2&px=999 "sched API comm 2.jpg")

Following that - run a GET on that schedule's rotation to grab the body of the request: <https://docs.opsgenie.com/docs/schedule-rotation-api#get-schedule-rotation>

![sched API comm 3.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/120258i7DF84184D01F32D3/image-size/large?v=v2&px=999 "sched API comm 3.jpg")

And finally, run a PATCH using the body from the previous request to update the rotation / schedule - and remove the user as a participant: <https://docs.opsgenie.com/docs/schedule-rotation-api#update-schedule-rotation-partial>

![sched API comm 4.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/120259iB84116DF68D9B4BD/image-size/large?v=v2&px=999 "sched API comm 4.jpg")

NOTE - when a user is removed from a rotation, that rotation will be rebuilt with the remaining users from the Stars On date set on the rotation. This could adjust who is currently on-call in a schedule. So in the PATCH or a following one, you may also need to update the rotation's Starts On date to reflect who should be on-call.

Hope this helps! Let us know if you have any questions or issues.

-Nick

comments: author: Amit Kumar
body: While Nick's answer is technically correct, I would suggest to first by first starting to remove the user from all teams.

For some reason, when a user is a member of a team, it also says they are a member of the schedule and escalation policy of that team as well, even if they aren't physically in a rotation or escalation policy.

The endpoints needed for this are:  
<https://docs.opsgenie.com/docs/user-api#list-user-teams>  
<https://docs.opsgenie.com/docs/team-member-api#remove-team-member>

After removing the Team membership, then I would proceed as Nick suggested.


author: Mikhail
body: .  

<br />


author: Mikhail
body: How to add 1 seat for OpsGenie over API?  
Now I adding here <https://app.opsgenie.com/settings/billing/subscription> over web, but I need over API


author: Jason Barry
body: Does anyone already have this logic built out? I would start coding for this, but it would save me a lot of time if there is something out there already.


Tags: api

rest-api