Get output for each item from a list of items

I have two API calls in the same collection. I got a list of alerts from my previous API call. Now in my second API call, I want to use each alert from the list to get more information on it. Now this is where I am facing a problem, the second API call keeps on picking the first element of the list and doesn’t go through each element.
I tried the ‘Shift’ function and for loop, but both are not working.

Here is my code:
1st API script
Get {{URL}}/alerts-list

a = JSON.parse(responseBody)
pm.collectionVariables.set("ID", a);

=> got a list of alerts here successfully in collection variable ID

2nd API script - detail
Get {{URL}}/alerts-info/{{alertIDnow}}/
Pre-request scripts

const Aid = pm.collectionVariables.get("ID")
pm.collectionVariables.set("alertIDnow", Aid.shift());

=> detail is the name of the 2nd API script. When using a collection runner it only fetches the first element from the Aid list and doesn’t iterate through the list.

Please help me out. I am using Postman web application. Been stuck on this for days.

Hey @anchalsingh12 :wave:

Welcome to the Postman community! :postman:

This recent thread might give you some scripting inspiration, sound like you’re getting into the same issue with selecting the first item each time.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.