# Runner custom request order

**URL:** <https://community.postman.com/t/runner-custom-request-order/5835>\
**Category:** Help Hub\
**Tags:** runnercollection, runner\
**Created:** [June 10, 2019, 7:17am UTC](https://community.postman.com/t/runner-custom-request-order/5835 "2019-06-10T07:17:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![trueicecold](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@trueicecold](https://community.postman.com/u/trueicecold)\
**Post date:** [June 10, 2019, 7:17am UTC](https://community.postman.com/t/runner-custom-request-order/5835/1 "2019-06-10T07:17:37Z")

</div>

Hello all,

I have several request I want to unitest, problem is some of the, are dependant on other previous requests:

Request 1  
Validate response and save header  
Use header in Request 2  
Validate Request 2

Request 1  
Validate response and save header  
Use header in Request 3  
Validate Request 3

etc…

Is it possible to call the first request more than once, and initiate the requests as I see fit? Or is this not supported in Postman?

Thanks!

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [June 10, 2019, 7:32am UTC](https://community.postman.com/t/runner-custom-request-order/5835/2 "2019-06-10T07:32:02Z")

</div>

Have you looked into `postman.setNextRequest();`

It’s a game-changer 🙂

[https://learning.getpostman.com/docs/postman/collection\_runs/building\_workflows/](https://learning.getpostman.com/docs/postman/collection_runs/building_workflows/)

[https://learning.getpostman.com/docs/postman/scripts/branching\_and\_looping/](https://learning.getpostman.com/docs/postman/scripts/branching_and_looping/)

---

<div class="post-metadata">

**Author:** ![trueicecold](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@trueicecold](https://community.postman.com/u/trueicecold)\
**Post date:** [June 10, 2019, 7:52am UTC](https://community.postman.com/t/runner-custom-request-order/5835/3 "2019-06-10T07:52:23Z")

</div>

Thanks @ [  
pfarrell](https://community.postman.com/u/pfarrell), this seems to help a lot when determining the order of requests. However, after request1 is done, along with all of its setNextRequest() commands, it will still continue to the next requests in order, right? That’s not good, for me, anyways…

I’m tying to construct a very know of test cases:

## test 1

Request 1  
Request 2

## test 2

Request 1  
Request 3

## test 3

Request 2  
Request 3

etc… I guess I need several runners? How do I create a runner only for 2 request and not all of the request in a collection?

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [June 10, 2019, 7:56am UTC](https://community.postman.com/t/runner-custom-request-order/5835/4 "2019-06-10T07:56:56Z")

</div>

You could add some logic into the tests and have some kind of “counter” value, so when it’s 1 (using postman.setNextRequest()), you could say to run requests 1 and 2, if the counter value is 2 then run 1 and 3 etc.

Removing the whole duplication thing in Postman seems to be one of the biggest challenges, in my opinion.

Check out the below post on keeping your tests DRY as there are some good answers from other experienced Postman users:

> [@How to implement DRY / good coding practices?](https://community.postman.com/t/how-to-implement-dry-good-coding-practices/5500/):
>
> Hi all, I have a lot of collections which are relatively similar, following this pattern. Send a POST request with a json body Send couple of GET requests and verify the results via tests Main difference between those collections is The json body of the post request The test (results) of the GET requests The endpoints of the POST/GET requests This results in a lot of duplication. Basically what I´m doing is to copy a collection, and modify the body and adapt the tests, which is resulting …

---

<div class="post-metadata">

**Author:** ![trueicecold](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@trueicecold](https://community.postman.com/u/trueicecold)\
**Post date:** [June 10, 2019, 8:02am UTC](https://community.postman.com/t/runner-custom-request-order/5835/5 "2019-06-10T08:02:07Z")

</div>

Thanks again, after reading this a bit, and considering my API is going to get considerably bigger than it is now, duplicating collections for each test case seems like a huge overhead…

Was thinking about using Chai on my own and create my own tests using js, but we can’t really integrate it with postman… Sad day…

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [June 10, 2019, 8:10am UTC](https://community.postman.com/t/runner-custom-request-order/5835/6 "2019-06-10T08:10:25Z")

</div>

Yep, I’ve been there 🙂

I may be biased here, but checkout my posts on using “beforeEachHooks” in Postman:

So if you have a User API and you want to create a new user per test scenario so you have no persisting data from other tests.

You’d want a “create user” request to run first, then run request 2. Then go back and create a new user and run request 3. etc.

I’ve used this method at my current place of work and it has dramatically cut down maintenance. There is a little bit of a learning curve whenever new testers start using my API tests but it’s SO much better than duplicating and maintaining the same request.

> [@My Code Snippets From The London Postman Summit - Paul Farrell](https://community.postman.com/t/my-code-snippets-from-the-london-postman-summit-paul-farrell/4591):
>
> Hey all, First of all, it was great meeting some of you that attended the Postman event. For those attended, I hope you enjoyed or got something out of my talk slight_smile I’ve been asked to upload the slides I used during my talk but the slides on their own are pretty pointless, as 90% of the content was me talking over images. So I’ll just upload the code examples used in the last third of the slides. For those that didn’t attend or need their memory jogging - this is about using “hooks”…

[https://community.postman.com/t/implement-hooks-to-postman-to-improve-maintainability-of-test-collections-before-beforeeach-aftereach-etc/3778](https://community.postman.com/t/implement-hooks-to-postman-to-improve-maintainability-of-test-collections-before-beforeeach-aftereach-etc/3778)

**My post on the below thread has example collections etc.**

> [@How to implement DRY / good coding practices?](https://community.postman.com/t/how-to-implement-dry-good-coding-practices/5500/6):
>
> @danny-dainton@chrissbaumann EDIT: I’ve attached an example collection/environment to see it in action. Just click the Download link at the top and import them into Postman. Postman Collection: [{ "info": { "\_postman\_id": "ae24430b-d0c0-4b0c-91ff-90a060d4611b", "name - Pastebin.com](https://pastebin.com/a57NL4gz) Postman Environment: [{ "id": "4d43c020-4c8c-43d8-b1ae-acaaecf7bd40", "name": "Restful Booker", - Pastebin.com](https://pastebin.com/aMEDjkU4) For me, keeping your tests DRY in Postman is one of the biggest challenges and it’s something that …
