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

**URL:** <https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [August 16, 2021, 6:19pm UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796 "2021-08-16T18:19:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chathurahjm](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@chathurahjm](https://community.postman.com/u/chathurahjm)\
**Post date:** [August 16, 2021, 6:19pm UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796/1 "2021-08-16T18:19:10Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) 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)_:

 ![2021-08-16_23-45-12](https://us1.discourse-cdn.com/getpostman/original/2X/f/f520049049bb40b8488ecc6ab65e7b15a2b99da3.jpeg)

_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:

---

<div class="post-metadata">

**Author:** ![vikram.sahu](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vikram.sahu/32/5449_2.png) [@vikram.sahu](https://community.postman.com/u/vikram.sahu)\
**Post date:** [August 17, 2021, 3:00am UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796/2 "2021-08-17T03:00:27Z")

</div>

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.

- [Use result of API call as input to another API](https://community.postman.com/t/use-result-of-api-call-as-input-to-another-api/9392)
- [New to Postman Part 5: chaining requests - YouTube](https://youtu.be/shYn3Ys3ygE)
- [Intro to Postman Part 5: chaining requests - YouTube](https://youtu.be/DToBC12Ztnk)

I hope this helps you.

Thanks

---

<div class="post-metadata">

**Author:** ![chathurahjm](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@chathurahjm](https://community.postman.com/u/chathurahjm)\
**Post date:** [August 17, 2021, 3:58am UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796/3 "2021-08-17T03:58:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chathurahjm](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@chathurahjm](https://community.postman.com/u/chathurahjm)\
**Post date:** [August 17, 2021, 6:05am UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796/4 "2021-08-17T06:05:31Z")

</div>

> [@vikram.sahu](#):
>
> New to Postman Part 5: chaining requests - YouTube

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}](https://restful-booker.herokuapp.com/booking/%7B%7Bbooking_id%7D)}”)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [August 17, 2021, 6:15am UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796/5 "2021-08-17T06:15:16Z")

</div>

Hi @chathurahjm,

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

Example:

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/7/720d6abbf74ea4b48b25109cb8e32fad4962cd2d.png)

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 😊

---

<div class="post-metadata">

**Author:** ![vikram.sahu](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vikram.sahu/32/5449_2.png) [@vikram.sahu](https://community.postman.com/u/vikram.sahu)\
**Post date:** [August 17, 2021, 6:21am UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796/6 "2021-08-17T06:21:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chathurahjm](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@chathurahjm](https://community.postman.com/u/chathurahjm)\
**Post date:** [August 18, 2021, 4:19am UTC](https://community.postman.com/t/how-to-loop-the-2nd-request-based-on-1st-request-output/26796/7 "2021-08-18T04:19:33Z")

</div>

> [@chathurahjm](#):
>
> I tried , What I need is I need to e

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 🙂
