Rest Assured Automation : Getting "mockRequestNotFoundError" even after specifying "x-mock-match-request-body : true" header for Post request

Hi,

I have created the simple mock server with single POST request for login.

The request details are as follows :

  • Path = {{url}}/api/v1/user/login
  • Body = { "username":"test@test.io", "password":"1" }

I have created 3 examples such that :

In Postman after adding “x-mock-match-request-body : true” I am getting correct response as per the body data passed to the request.

My aim is to write script using Java + Rest Assured which will call this Post /user/login API and I will get the response as per the passed body data.

The sample script is :

RestAssured.given().header("x-mock-match-request-body", "true").
                    body("{\"username\":\"test@test.io\",\"password\":\"wrong\"}").post("{{url}}/api/v1/user/login");

But I am getting “mockRequestNotFoundError” error. I have checked all the body data is correctly passed and request URI is also correct but still getting this issue.

Here are the sample logs :
Request method: POST
Request URI: {{url}}/api/v1/user/login
Proxy:
Request params:
Query params:
Form params:
Path params:
Headers: x-mock-match-request-body=true
Accept=/
Content-Type=application/json; charset=UTF-8
Cookies:
Multiparts:
Body:
{
“username”: “test@test.io”,
“password”: “wrong”
}

I have tried different combinations for headers like following :

  • When header(“x-mock-match-request-body”, ““true””) => Default response (expected is error response for invalid username/password case)
  • When header(“x-mock-match-request-body”, “true”) => mockRequestNotFoundError
  • When header(“x-mock-match-request-body”, true) => mockRequestNotFoundError

It will be very helpful if someone confirm the behaviors or let me know if i am doing something wrong here. If this is the issue on Postman side or from Rest Assured side.

Thank you in advance :slight_smile: