# Running collection within collection

**URL:** <https://community.postman.com/t/running-collection-within-collection/8154>\
**Category:** Help Hub\
**Created:** [October 3, 2019, 12:06pm UTC](https://community.postman.com/t/running-collection-within-collection/8154 "2019-10-03T12:06:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielcd](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@danielcd](https://community.postman.com/u/danielcd)\
**Post date:** [October 3, 2019, 12:06pm UTC](https://community.postman.com/t/running-collection-within-collection/8154/1 "2019-10-03T12:06:13Z")

</div>

Hi all,

This might be a newbie question, so forgive my foolishness. However I’ve searched throught the forums and couldn’t find the answer.

I have a collection of tests (A) which tests some part of API and returns some data. Let’s call it “shared one”.  
I have another collection (B) which depends on data returned by A.  
I have one more collection (C) which also depends on data returned by A.

What I want to achieve is some sort of collection grouping.  
I run C, which runs A first.  
I run B, which runs A first.

Of course, I could just add all the tests from A to every other collection, however, I would have to make any change of tests in shared collection in other collections too, al the time… yuck.

Tried to find a solution using loading the collection file using the fs module. Not supported ☹

I’ll appreciate any idea, Thanks a lot.

---

<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:** [October 3, 2019, 12:15pm UTC](https://community.postman.com/t/running-collection-within-collection/8154/2 "2019-10-03T12:15:07Z")

</div>

Hey @danielcd  
Welcome to the Postman community.  
It sounds like you want to use “postman.sendNextRequest()” to control your workflow.  
There is no “run this collection as a pre-requisite” in Postman but I’m doing exactly what you’re wanting in my workspace.

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

I’ve posted about this quite a bit in the forum:

> [@postman.setNextRequest() ignore other requests in collections](https://community.postman.com/t/postman-setnextrequest-ignore-other-requests-in-collections/5787/2):
>
> Assuming your requests are in this order in your collection 1 \> 2 \> 3 and you want to run your requests in the below order using postman.setNextRequest() 1 \> 3 \> 2? postman.setNextRequest() is working as expecting in your example. If you want to call request 2, then you’d need to use postman.setNextRequest("name-of-request-2") in request 3, so after request 3 has been completed it’ll run request 2. Bear in mind, that after request 2 it’ll naturally go to the next request in your collection w…

> [@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”…

> [@How to implement DRY / good coding practices?](https://community.postman.com/t/how-to-implement-dry-good-coding-practices/5500/4):
>
> thanks for the mention @danny-dainton. I have to admit that I do find Postman pretty absent on nice re-use of various parts in the system, in particular code re-use, request re-use and dynamic flow execution. I have been battling with it for over a year and found some workable work-arounds. It’s all still a bit rough, but I want to start writing them up here over the next few months. In essence, we have teams with dev’s and QA’s all adding to the same collection of grouped and alphabetised end …

And here’s my talk at this year’s PostCon where I specifically talk about this:

[![](https://img.youtube.com/vi/lmGrMA4I5CI/maxresdefault.jpg "How Gear4Music Went from 0-1000 API Tests: Paul Farrell, Gear4Music | POST/CON 2019") ](https://www.youtube.com/watch?v=lmGrMA4I5CI)

---

<div class="post-metadata">

**Author:** ![danielcd](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@danielcd](https://community.postman.com/u/danielcd)\
**Post date:** [October 3, 2019, 12:42pm UTC](https://community.postman.com/t/running-collection-within-collection/8154/3 "2019-10-03T12:42:23Z")

</div>

Hi @postman-paul540, thank you for the advice.  
I’ve already checked the setNextRequest(), however the internal logic of the calling of the requests would be insane. There is an API with a serious number of endpoints and I just can’t keep requests for each of them all in one huge collection.  
Each of the collection must start with some tricky login sequence and that’s why I wanted to share this piece of code between collections.

I’m thinking about going up one level and write some commandline script, which will contain separate newman runs, each for one collection. However I have to solve the passing the output data out of the Postman, which is gonna be tricky again.

---

<div class="post-metadata">

**Author:** ![danielcd](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@danielcd](https://community.postman.com/u/danielcd)\
**Post date:** [October 3, 2019, 12:58pm UTC](https://community.postman.com/t/running-collection-within-collection/8154/4 "2019-10-03T12:58:42Z")

</div>

I have discovered this Postman Collection SDK which seems to do exactly what I need.  
[http://www.postmanlabs.com/postman-collection/](http://www.postmanlabs.com/postman-collection/)  
However, it doesn’t seem to work. Postman fails on " fs.readFileSync is not a function".

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [October 3, 2019, 5:33pm UTC](https://community.postman.com/t/running-collection-within-collection/8154/5 "2019-10-03T17:33:54Z")

</div>

> [@danielcd](#):
>
> fs.readFileSync is not a function

What node venison are you using?  
Can you post the whole error?

---

<div class="post-metadata">

**Author:** ![danielcd](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@danielcd](https://community.postman.com/u/danielcd)\
**Post date:** [October 4, 2019, 7:29am UTC](https://community.postman.com/t/running-collection-within-collection/8154/6 "2019-10-04T07:29:55Z")

</div>

> [@danielcd](#):
>
> adFileSync is

$ node -v  
v8.10.0

$ npm info postman-collection  
dist-tags:  
beta: 3.5.4-beta.1 latest: 3.5.4

The error comes from Postman

> There was an error in evaluating the Pre-request Script: TypeError: fs.readFileSync is not a function

Console says

> TypeError | fs.readFileSync is not a function
