K
Kinde4mo ago
madmaniac

Remove all roles of a user

Hello, I'm trying to remove all the roles of a user using one API call. Let's say I have a user with 5 roles. I tried using "PATCH /api/v1/organizations/{org_code}/users". In this request, if I pass in 1 role (or more), the user is updated and will have 1 role only. But if I pass in no roles (empty array), then the request returns 200, but does nothing. The users still has all previous roles. Do I need to use "DELETE /api/v1/organizations/{org_code}/users/{user_id}/roles/{role_id}"? That would be cumbersome. I would first have to request the current roles, and then do 5 calls to delete each one of them. Instead, I could use "PATCH /api/v1/organizations/{org_code}/users" to reduse the user's roles from 5 to 1, and then use "DELETE /api/v1/organizations/{org_code}/users/{user_id}/roles/{role_id}" to delete the user's role. But that would be weird. What is the best approach here?
7 Replies
Oli - Kinde
Oli - Kinde4mo ago
Hey @madmaniac, Your use-case to remove all roles from a user is very reasonable and I completely understand that the current way to do this via the API is not reasonable. I will need to speak to my teammates about this early next week and get back to you. Is it okay if you use the mechanisms you mentioned above for now?
madmaniac
madmaniacOP4mo ago
@Oli - Kinde yes, no problem. Thank you
Oli - Kinde
Oli - Kinde4mo ago
Hey @madmaniac, It's on our radar to make the experience better to remove all roles of a user via API. I would suggest using the following mechanism for the moment:
Instead, I could use "PATCH /api/v1/organizations/{org_code}/users" to reduse the user's roles from 5 to 1, and then use "DELETE /api/v1/organizations/{org_code}/users/{user_id}/roles/{role_id}" to delete the user's role
I know it's a weird way to do it, but its the best way for now.
madmaniac
madmaniacOP4mo ago
@Oli - Kinde Thanks you very much.
Oli - Kinde
Oli - Kinde4mo ago
Hey @madmaniac, After speaking to my team. We actually agreed that passing an empty array to "PATCH /api/v1/organizations/{org_code}/users" should remove all roles. We have now deployed a change so that when you pass an empty array to "PATCH /api/v1/organizations/{org_code}/users" all roles are removed.
madmaniac
madmaniacOP4mo ago
@Oli - Kinde Thank you very much for the quick fix!
Oli - Kinde
Oli - Kinde4mo ago
My pleasure
Want results from more Discord servers?
Add your server