One of the features in Postman allows users to save a specific field from the response body as a variable and then utilize that variable in a subsequent call.
For instance, after my initial call to the web service, the response body contains:
[ {
"id" : "11111111-1111-1111-1111-111111111111",
"username" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f386809681dec2b3968b929e839f96">[email protected]</a>",
}, {
"id" : "22222222-2222-2222-2222-222222222222",
"username" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0b5b3a5b2edf280a5b8a1adb0aca5eea3afad">[email protected]</a>"
} ]
A test is added:
postman.setGlobalVariable("user_0_id", JSON.parse(responseBody)[0].id);
Subsequently, I send another request with the URL:
http://example.com/users/{{user_0_id}}
Postman replaces {{user_0_id}}
with
11111111-1111-1111-1111-111111111111
.
This process works correctly. However, when I enhance the test for my first call with:
postman.setGlobalVariable("users", JSON.parse(responseBody));
In the second request to the webservice, using the URL:
http://example.com/users/{{users[0].id}}
The issue arises where {{users[0].id}}
remains unchanged and does not get replaced by
11111111-1111-1111-1111-111111111111
.
What should be the correct syntax for this scenario?