Mock responses that include request body

I have an API schema setup with swagger and imported it into Postman. Then I fixed some errors that occured during the import regarding the example responses. I took them directly from Swagger and they are valid responses according to my schema.

Now I’m trying to send a POST request to the mock server and I’m including a request body like so:

{
“name”: “Marius Dale”,
“id”: 1,
“nationality”: “N”,
“job”: “Frontend Engineer”
}

In my examples I have specified responses with error codes 201, 400 and 409. How do I make the examples work for let’s say different id’s?. So instead of the above I might be sending something like that:

{
“name”: “Marius Dale”,
“id”: 0,
“nationality”: “N”,
“job”: “Frontend Engineer”
}

Even though I’m specifying different request bodies in each example the mock server always returns just one of those responses, no matter what I type in. What am I doing wrong? Any help appreciated :slight_smile:

So, I am trying to figure the same thing out :frowning: I have an idea about the issue … I think it is ( matching algorithm ) and since we are putting the “difference” in the body and not in the URL, then the mock server always see’s it as the same endpoint and thus always returns the same value , I think. I have read as much as I can on it … but there doesn’t seem to be a means to get the the response engine to pull from the body … If you look here:
Matching Algorithm
You will see that steps 4 and 5 are really the only options we have … so if you look at step five, that may give you what you want … but then you have to give the explicit code there :frowning: which is a bummer. So you don’t have to hunt, here is 5:

Response code If the x-mock-response-code header is explicitly provided, filter out all examples that do not have a matching response code.

Anyhow, I will keep working on it and if you figure it out … please do let us know and I will do the same.

1 Like

Hm I actually suspected it to behave just like that. It’s a bummer indeed that they won’t allow you to mock these responses to POST requests or pretty much anything that includes a response body. So far I haven’t figured out a better way of doing it so thanks for the answer and your suggestion :wink:

As soon as I come to a better solution (if there is any) I will let you know!

Hey,@tombjarne96, just a quick update … I think I have an easier way than what is here … well at least it is easier for me :slight_smile:

Create your own custom header like:
x-myco-myapp-pm-mock-id
Then give it a number that is unique and easy to remember/understand [I used 1,2,3…] so that you can pass that in on each of your request to the mocked endpoints that need a specific return. You make your example look for that value and the matching alg will find it as highest.

For me that is way easier than getting the example UUID or “name” of the example and using the: x-mock-response-name and x-mock-response-code.

Anyhow just wanted to pass on some more thinking/working.

1 Like