# Dynamic request collection

**URL:** <https://community.postman.com/t/dynamic-request-collection/36469>\
**Category:** Help Hub\
**Tags:** newman-project, tests\
**Created:** [June 22, 2022, 2:04pm UTC](https://community.postman.com/t/dynamic-request-collection/36469 "2022-06-22T14:04:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZivWu](https://avatars.discourse-cdn.com/v4/letter/z/67e7ee/32.png) [@ZivWu](https://community.postman.com/u/ZivWu)\
**Post date:** [June 22, 2022, 2:04pm UTC](https://community.postman.com/t/dynamic-request-collection/36469/1 "2022-06-22T14:04:05Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

Hi all,

I’m trying to use Newman with CI.  
After I read the Newman guide, I found Newman only can run with a collection.  
But I have a question below.

For example, there have five requests. A, B, C, D, E  
In different scenario may have different combination with request.  
Scenario 1 : First call A request then call B then call C  
Scenario 2 : First call A request then call C then call D  
Scenario 3 : First call A request then call C then call E

The worst way to use Newman with CI is create three collection.  
First collection have three request (A, B, C)  
Second collection have three request (A, C, D)  
Third collection have three request (A, C, E).

But there have a problem, if my request A API format change I need to change three request in these collection.

Is there a dynamic way to build request collection items?

Best regards,  
Ziv

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 22, 2022, 5:44pm UTC](https://community.postman.com/t/dynamic-request-collection/36469/2 "2022-06-22T17:44:57Z")

</div>

Hi @ZivWu

I think you would have to use the `postman.setNextRequest("request_name");` option and build conditions into your test tab.

Example;  
If request A returns value X then run request C  
else run request D

You can find more info on request workflows here:

> **[Building request workflows | Postman Learning Center](https://learning.postman.com/docs/running-collections/building-workflows/)**
>
> Building request workflows: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![ZivWu](https://avatars.discourse-cdn.com/v4/letter/z/67e7ee/32.png) [@ZivWu](https://community.postman.com/u/ZivWu)\
**Post date:** [June 23, 2022, 1:42am UTC](https://community.postman.com/t/dynamic-request-collection/36469/3 "2022-06-23T01:42:56Z")

</div>

Hi @w4dd325

Yes, I’m useing this way currently. But it will make my postman script very hard to maintain.

My way is use a variable to set current scenario number.  
Then use the setNextRequest base on current scenario number.  
In A request postman script will check current scenario number and setNextRequest.  
Just like if current scenario number is 1 request A next go to request B, If current scenario number 2 request A next go to request C.  
In the request B also need check the current scenario number to setNextRequest to C.  
In the request C need check the current scenario number and setNextRequest to request A and set current scenario number to 2.

In this way will make my request postman script hard to maintaine.(very long and worse readable)  
Also if I need to add a new scenario I have to edit many request’s postman script.

I’m searching about is there a way use program to build collection content?

Best regards,  
Ziv

---

<div class="post-metadata">

**Author:** ![ZivWu](https://avatars.discourse-cdn.com/v4/letter/z/67e7ee/32.png) [@ZivWu](https://community.postman.com/u/ZivWu)\
**Post date:** [July 22, 2022, 9:14am UTC](https://community.postman.com/t/dynamic-request-collection/36469/4 "2022-07-22T09:14:07Z")

</div>

Hi all,

If you have same question like me.  
I found a better way. [Introduction | Postman Labs Docs](https://learning.postman.com/labs/postman-flows/getting-started/flows-overview/)  
Postman flows is beta currently and it will support CI ([newman](https://github.com/postmanlabs/postman-flows/discussions/19))

Best regards,  
Ziv

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 12:54pm UTC](https://community.postman.com/t/dynamic-request-collection/36469/5 "2024-12-12T12:54:13Z")

</div>

Closed on December 12, 2024, 12:54pm UTC

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