Could I ask what the outcome is there you’re seeking?
Do you need to verify a certain field in the response to check if it’s a certain format or do you just need some dynamic data placed into the field on the example request?
Sorry I still don’t really understand what you’re trying to achieve, if you could elaborate more and explain the use case in more detail, it might help me and others to understand the problem.
A couple of points on the examples for Mock servers - You currently cannot use regex in the example request body, as you have it but you can add a layer of dynamic data to them.
The built-in Dynamic variables can be used in the examples to create random fake data - Here’s a basic request body:
i want to send request with customerid, the number will be 4 digits(1234,3234,7891)
i want the example to take this number lets take 1234 as example and catch it with postman mock example
because i want the example to check the number of digits{4} and not the value 1234
i want → “customerid” : [0-9]{4}"
not “customerid:1234”
next day i want to send 3434 and the same example will use…
the customer will not be 1234 every time… it will be 4 digits and that should be ok…
I did mention that you couldn’t do that and I was offering a different solution.
I understand what you want to send in the body and what you would like in the example but that’s not possible.
There are ways to match the request body but using a specific header but again, that’s not going to give you the regular expression syntax that you want to see/use in an example.
I think the closest you could get to what you require is to create a request that contains the x-mock-match-request-body header with the value true and then create a series of examples with those different request/response bodies.
The example would need to match for the method, URL and request body and then you can add whatever you need to the response body.
ok thanks… so this tools implemented what i need…
because i dont know which customerid the API will send, i just know it will send post and inside the body in json structure the customerid will be numeric with 4 digits (1111,3245,6532…)
i cant create example request with constant number (1234)… and i can send it with the url because its an other request
Thanks, this was exactly what I was looking for! The variable in the example response doesn’t get populated if you use the :var syntax. I really think this should be included in the official documentation, as I have spent more than an hour with Google and trial-and-error on this. It feels like a common use case for mock servers, to include a path or query variable in the mocked response.
Now I would also like to include fields from the request body in the response body. So, I would like to define my Example request body as something similar to (JSON):
{
"name": "{{name}}",
...
}
And get the Example to respond with:
{
"name": "{{name}}",
...
}
I.e. that the “name” field’s value sent in the request gets copied to the “name” field in the response. Is this possible?
For anyone else reading this thread, copying fields from request to mocked response is currently not possible. A Github issue has been created requesting this feature:
hello,
i’ve found this post searching for a feature like this,
Is this something planned ?, is this something already feasible with Postman ?
the use case we have is mocking dynamic graphql request,
from my understanding they cannot be predicted unless some kind of pattern matching algorithm for the request body is possible.
If you can save a response value from a request test, as the link below describes, I wonder if you’d be able to save a request value as well, and then use it?