Auth0 Home Blog Docs

Error when trying to remove roles from user



When I’m trying to remove roles from a user I get “Invalid request payload JSON format” error.

public static async Task<string> RemoveRolesFromUser(string user_id, string[] roles, string token) {
    TaskCompletionSource<string> task = new TaskCompletionSource<string>();
    RestClient client = new RestClient($"{user_id}/roles");
    RestRequest request = new RestRequest(Method.DELETE);

    request.AddHeader("Content-type", "application/json");
    request.AddHeader("Authorization", $"Bearer {token}");
    request.AddParameter("application/json", roles, ParameterType.RequestBody);
    request.RequestFormat = DataFormat.Json;

    client.ExecuteAsync(request, res => {
        if (res.ResponseStatus == ResponseStatus.Completed) {

Switching Method.DELETE to Method.PATCH for adding roles works just fine so I don’t understand why DELETE would throw a format error.

Also, in the API explorer it says “/users/{role_id}/roles” as endpoint but I think it’s a typo? It should be “/users/{user_id}/roles”, right? In the example it says “DELETE https://{extension_url}/users/{user_id}/roles” Authorization Extension API Explorer


Found the issue, AddParameter isn’t parsing the array accordingly. This worked:

request.AddParameter("application/json", JsonConvert.SerializeObject(roles), ParameterType.RequestBody);