I want to orchestrate two requests in Postman. The first response will give me a variable. I save this id to a global variable id
. In Postman this variable is usually accessible via {{id}}
.
Then I send a second request with this id (like GET foo.bar/{{id}}
). Now I want to check, if the id is in the result as well.
This is what I tried in the test code:
var jsonData = pm.response.json();
pm.expect(jsonData.id).to.eql({{id}});
where id
is the variable from the first response (e.g. 72b302bf297a228a75730123efef7c41
).
The response for the second request looks sth. like this:
{
"id": "72b302bf297a228a75730123efef7c41"
}
Here some examples which did not work either:
var jsonData = pm.response.json();
pm.expect(jsonData.id).to.eql("{{id}}");
var jsonData = pm.response.json();
var myId = {{id}};
pm.expect(jsonData.id).to.eql(myId);
My excpectation is, that the test will be positive and the `id from the request will be found in the response.
Do you have an idea how to solve this problem?
Thanks for the help.
The
{{...}}
syntax cannot be used like that, in the sandbox environment, you would need to access it this way.pm.expect(jsonData.id).to.eql(pm.globals.get('id'))
The test syntax would be: