There's several ways to do this but I got it working by using two requests. The first to get the data, the second as the iteration request. You can see the full workflow working on this folder I've created for you. To test it yourself, just fork the collection and run the whole folder on one of your workspaces.

At a high level this is what you do:
- Create a folder so you can run these requests as a "flow".
- Create one request that gets all "marks", store "marks"
- Create another request that:
- 3.1 While there are marks, remove one mark
- 3.2 Add
mark
as a query param
- 3.3 Save the remaining marks, if none left exit.
- 3.4 Call the same request again
Code for the first request on Tests
:
const responseDate = pm.response.json()
const marks = responseDate.marks.map(x => x.name)
console.log("Obtained a list of brands:", marks)
console.log("Saving brands into marks collection variable")
pm.collectionVariables.set("marks", marks)
postman.setNextRequest("Brand detail");
Code on second request pre-request script
:
let marks = pm.collectionVariables.get("marks")
const currentMark = marks.shift()
pm.request.addQueryParams(`marque=${currentMark}`);
if (marks.length > 0) {
pm.collectionVariables.set("marks", marks)
postman.setNextRequest("Brand detail");
} else
{
// Redundant
postman.setNextRequest(null)
}
You can see on the first one I used your real URL, on the second one I couldn't authenticate so I used the Postman Echo API just to be able to send the request.
NOTE: You have to run the whole folder to chain the requests, otherwise postman.setNextRequest()
won't work.