RestSharp - How to validate response after sending a PATCH request if response status code is 400

Skip to first unread message

Mahathi Addanki

Aug 17, 2022, 4:35:02 PM8/17/22

I am sending a PATCH request to an API in our system using Restsharp library. For the data under test, the API returns 400 response code with below response body

    "display message" : "Validation Failed"
    "Validation message": "id is required"

I have to validate response code and response contents. I see that the response code is received in httpresponseCode, I am not able to figure out how i can retrieve the response body contents

                RestClient client = SetUrl(endpoint);
                var token = Readtoken();
                RestRequest request = new RestRequest().AddStringBody(jsonData, DataFormat.Json).AddHeader("Authorization", "Bearer " + token);
                return await client.PatchAsync(request);             
            catch (HttpRequestException ex)
                var httpresponseCode = (int)ex.StatusCode;
                log.InfoFormat("entered into http exception while sending patch");

Thanks in Advance

Reply all
Reply to author
0 new messages