Using variables in a nested loop in Postman Flow


I have found Postman flow to be quite interesting and am using it to test a workflow.

The problem is as below(added labels in screenshot):

  1. At Level 1, I have a list of projects, each having unique project_id. I am looping each of the project_id using Loop 1 to the users within that project

  2. At level 2, I have the list of user_id for the respective project. I am looping through each of the users using Loop 2 to reach Level 3.

  3. At Level 3, I would need both - the project_id and the user_id to send an API request.

However, I am not able to get the corresponding project_id at Level 3. Could you please suggest a solution ?

Thanks in advance!

Hi @amitaman001

Welcome to the forums!

I recreated your flow with some mock servers.

You can do the following:

The evaluate block (using TypeScript, which you can enable by selecting it from the drop down that says ā€œFQLā€ in the top right of the block) can map the projectId to the userIds. They can be accumulated in a collect block which can then be flattened so you have a single list to iterate through with a for block for level 3 which will have a userId and projectId pair.

Let me know if you run into any issues.

Thanks @flows-daniel for the prompt response. It worked perfectly !

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