When I build a mock server in a private workspace and set the
x-mock-match-request-body header to true, the response I get with an incorrect body is a fail (as expected / left side of image), but if I hit the API from a public workspace the call passes even if the data is incorrect (right side of image).
Details (like screenshots):
How I found the problem:
Calling the privately created mock server from a public workspace.
I’ve already tried:
The x-mock-match-request-body header is currently set in the private workspace POST request (appears to work for the private workspace only).
Added the x-mock-match-request-body header to the POST example in the private workspace.
Added the x-mock-match-request-body header to the POST request in the public workspace.
The mock matching algorithm can be a little tricky. Postman anticipates which response to return based on what you save in the example (e.g.).
The best way I have found to elicit a very specific response, without Postman defaulting to a different saved example, is to be very specific in the saved example and then submit that information in your request. In your scenario, I wonder if you need to submit the header in the request (in addition to saving it in the example).
Thanks for the reply.
x-mock-match-request-body header also work for params?
I’m wondering if I could use params instead to make it more explicit …
I have some examples of mock servers working now but was trying to get it to display an error in the response body if the query params or request body was incorrect even by only 1 letter or word.
But it appears that it still defaults to “success” because the majority of the request is correct.
Is there any way of setting a mock server to be correct if for example, a param was a = 1 but if a = anything other than 1 it fails?
I feel like I’m trying to stretch the functionality here a bit, but it would be great if this was possible.
If not, do you know of any other online service that would offer this sort of functionality?
(Ideally, I’d like to stick with Postman mocks if possible though).
Been playing around with this for a while now and the closes I have come to getting the desired output is by using MockLabs to create the mock servers. It has a really useful feature that allows you to choose “matches” or “doesNotMatch” for query params… When I get 5 minutes Im planning to raise a feature request for this on Postman as it would be a fantastic addition!!
Nice! Please do open a feature request, or chime in on one of these here about mock matching: Issues · postmanlabs/postman-app-support · GitHub
Figured out the issue … only took a few months
When exporting and importing the collection, the ‘examples’ appear to show as passed when incorrect information is entered. However, I deleted the examples and added them in fresh and it appears to work fine again.
Slightly odd behaviour, but just happy it works again!
Not sure I understand. If you export and import the collection, the mock doesn’t travel with it. Did you create a new mock? (on the imported collection)?
I had been copying and moving collections, but when I “mocked the collection” … even though the “examples” were identical to previous ones, they would only show an accurate pass/fail when I deleted and recreated them.
It’s bizarre, I’ll see if I can get a recording of what I mean.
Right, so the first gif shows the behaviour of my mock… I have 4 values and if I change the bottom one from 2 to 1 it fails, and if I change it back to 2 it passes again.
However, if I duplicate this POST request (even without changing anything) the examples stop working.
You can see in the following gif that when I now change the bottom value from 2 to 1 it states a “passed” message and the same for when I change it back to 2… it never fails.
But, if I delete and recreate the examples, it then works again.
Hope that makes sense, it’s a tough one to explain.
Those are really long gifs
Can you include screenshots of the Pass and Fail examples under the first request? Or move the collection into a public workspace, so I can inspect it?
I see the second request behaving as expected:
answer4=2 returning Pass example
answer 4= or
answer4=1 returning Fail example
Strangely enough, I can’t replicate the issue now.
Here is the pass example;
And the fail example;
If I can narrow down what causes it to stop displaying correctly Ill let you know, but it appears to be intermittent.
(fyi - the challenge I messaged you about a while ago is coming together nicely now, may have something to show soon!)