I am trying to add some new requests to existing collection. The first request is getting the values, which gives me the result as an object array with ids. I want to use the ids from the object and perform an update with another request.
How can I iterate over the ids for the next request.
I tried using the pm.collectionVariables
and assign the values and used setNectRequest
in a for loop. It only executes once with the last id.
My GET request:
URL: {{api_url}}/resourcetypes
Tests:
let responseJson = pm.response.json();
let filteredResourceTypesIds = responseJson.values.map((type) => type.id)
pm.collectionVariables.set("filteredResourceTypesIds", filteredResourceTypesIds);
if (!filteredResourceTypesIds || filteredResourceTypesIds == null || filteredResourceTypesIds == undefined) {
return;
}
for (i = 0; i <= filteredResourceTypesIds.length; i++) {
console.log(i)
pm.collectionVariables.set("resourceTypeId", filteredResourceTypesIds[i]);
postman.setNextRequest("Add Property");
}
My Patch Request :
URL: {{api_url}}/resourcetypes/{{currentRsourceTypeId}}
Pre-script: let currentResourceTypeId = pm.collectionVariables.get("resourceTypeId");