I created a “Get All” request to get a list of objects. In the request’s "Post-request-scripts (tests) I’m executing “Get by ID” requests.
When executing this Request using the “Flows” feature, the response body displays one of the “Get by ID” responses instead of the “Get All” response.
Platform: OS X 23.5.0, 11.2.1-ui-240611-2311
Script:
var responseData = pm.response.json();
# Test for validating that each 'id' field in the response data is a string and exists
responseData.data.forEach(function(tag) {
pm.test(`'id' field should exist and be a string for tag ${tag.id}`, function () {
pm.expect(tag).to.have.property('id').that.is.a('string');
});
});
Do you have any other tests that you’re running that could be interfering with the response? I re-constructed an API similar to yours and added in your test and the response came back with the list.
If you run with just this test enabled does the issue still happen?
const tagList = pm.response.json().data;
// Ensure that the response contains an array of tags
pm.test("tag list should be an array", function () {
pm.expect(tagList).to.be.an('array');
});
// Iterate over each tag in the list
tagList.forEach(function(tag) {
const tagId = tag.id;
// Send a request to get the tag by ID
pm.sendRequest({
url: pm.environment.get('base_url') + 'tags/' + tagId,
method: 'GET',
header: {
'x-api-key': `${pm.environment.get("token")}` // Add your API key here
}
}, function (err, res) {
// Parse the response
const tagDetails = res.json();
// Run your tests on the tag details response
pm.test(`Response status code should be 200 for tag ${tagId}`, function () {
pm.expect(res).to.have.status(200);
});
});
});
});
Tell me if I can be of any service otherwise.
If you want to video-call with screen-sharing, I’m available GMT+3 10:00-19:00