RestSharp 106.10.1 is responding with Invalid JSON string on 204 Response

434 views
Skip to first unread message

John Boldt

unread,
Feb 17, 2020, 5:57:23 PM2/17/20
to RestSharp
I'm using RestSharp to interface with the Auth0 API. Everything's working fine except when deleting a user. I send the delete request as a DELETE and Auth0 successfully deletes the user.

Here is the response I'm getting from Auth0:

HTTP/1.1 204 No Content
Date: Mon, 17 Feb 2020 22:40:51 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Server: nginx


And here's what I'm getting in the RestSharp response:

System.Runtime.Serialization.SerializationException: Invalid JSON string
   at RestSharp.RestClientExtensions.ThrowIfError(IRestResponse response)
   at RestSharp.RestClientExtensions.DeleteAsync[T](IRestClient client, IRestRequest request)

Here's a code snippet:

        public virtual async Task<IRestResponse> DeleteAsync(string userId)
        {
            var request = new RestRequest($"{_config.ManagementApiBaseUrl}/api/v2/users/{userId}");
            request.Method = Method.DELETE;
                        var response = await Client.DeleteAsync<RestResponse>(request);
            return response;
        }

As mentioned above, the request is sent and processed on the Auth0 side, but then RestSharp tries to deserialize the (non-existent) response body.

What am I doing wrong?

Alexey Zimarev

unread,
Aug 16, 2020, 4:39:05 AM8/16/20
to RestSharp
The best thing would be for you to create an API client that would keep an instance of RestClient with its base URL set to _config.ManagementApiBaseUrl

Then, you use the URL segment parameter {userId} but I don't see where you set this parameter, so you call Auth0 literally with {userId} in the request, I think you can easily see it in your IDE because the function parameter (string userId) is not used anywhere.
Reply all
Reply to author
Forward
0 new messages