How to loop the 2nd request based on 1st request output

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

I have a 1 request which return some numbers. Base on that numbers, another request need to execute by passing one of those number each time.

As on the image at the top image, as for the response, I’m getting booking IDs.
And as for the 2nd image at the bottom, I have to pass the booking ID as a parameter to the 2nd request. And I need to do this for all the numbers I’m getting for the 1st request.

Details (like screenshots):

How I found the problem:

I have already got the 1st ID list to an array and try to pass them for the 2nd request, But that didnt work:

Hello @chathurahjm,

I am assuming you are looking for a chaining request feature within postman.

here are some solutions which is already shared within the community.

I hope this helps you.

Thanks

1 Like

Thanks, Will look in to this.If this is what I’m looking for, I will mark this as the solutions.

1 Like

I tried , What I need is I need to execute my 2nd API call while I’m in the 1st API call.

Something like below and that doesn’t work
postman.setNextRequest(“https://restful-booker.herokuapp.com/booking/{{booking_id}}”)

Hi @chathurahjm,

for postman.setNextRequest(“request name”) and not the request URL.

Example:

It should run the next post request, and the request name is used for postman.setNextRequest() method.

And if you need to run the GET request for certain number of times before POST, you need write a simple snippet with the iteration logic and conditions :blush:

1 Like

Thanks, rightly said @bpricilla,

I think @chathurahjm needs to write a script where he can iterate over the array of objects and then pass the value of each bookingId to the GET request before POST.

1 Like

Thanks. As I can remember, I tried with the request name as well and that doesn’t work too. Let me retry on this or else I will share the project :slight_smile:

1 Like