# How to run postman requests using Tags

**URL:** <https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628>\
**Category:** Help Hub\
**Tags:** newman-project, tests, variables, collections\
**Created:** [February 21, 2021, 1:30pm UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628 "2021-02-21T13:30:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [February 21, 2021, 1:30pm UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/1 "2021-02-21T13:30:32Z")

</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).

# Get all requests in the collection:

**you can also get information about all the requests in a collection by using :**

[https://api.getpostman.com/collections/{{collection\_UUID}}](https://api.getpostman.com/collections/%7B%7Bcollection_UUID%7D%7D)

**to get uuid and api key goto :**

[https://app.getpostman.com](https://app.getpostman.com/)

**Now for generating api key \>**

goto account settings \> api key and generate api key.

to get collection uuid goto specific workspace and collection and copy the uuid part from url:

![Image for post](https://miro.medium.com/max/1211/0*bS-1YwXf4GI2gaii.png)

**Note:** you can also get UUID by clicking collection and clicking info panel on the right side

![Image for post](https://miro.medium.com/max/397/1*mFhKG_cmjgxkRIcr6FXLNQ.png)

# Now in your collection

**Rename all requests as:**

```
get user details [Regression][Smoke][Somethingelse]
get account details [Regression]

```

# Then Create a new request called initial request and keep it as the first request in your collection:

**url:** [https://api.getpostman.com/collections/8xxxxtheuuidyoucopied](https://api.getpostman.com/collections/8xxxxtheuuidyoucopied)

**authorization:** apikey-header : key: X-Api-Key and value: yourapikey

**test-script** :

```
pm.environment.unset("requestToRun")
reqeustlist = pm.response.json().collection.item.map((a) => a.name)
requestToRun = reqeustlist.filter((a) => a.includes(pm.environment.get("tag")))
let val = requestToRun.pop()
pm.environment.set("requestToRun", requestToRun)
val ? postman.setNextRequest(val) : postman.setNextRequest(null)

```

Now set the envirnoment variable as what you want to look for eg: run script that contains text “Regression” then set `pm.environment.set("tag","Regression")`

**Now in your collection-pre-request add:**

```
if (pm.info.requestName !== "initial request") {
let requestToRun = pm.environment.get("requestToRun")
let val = requestToRun.pop()
pm.environment.set("requestToRun", requestToRun)
val ? postman.setNextRequest(val) : postman.setNextRequest(null)
}

```

# Output:

![Image for post](https://miro.medium.com/max/1335/0*upq4hlWWr7tvvOUo.png)

Ran only reqeusts that has “Copy” in its name

# Example collection:

[https://www.getpostman.com/collections/73e771fe61f7781f8598](https://www.getpostman.com/collections/73e771fe61f7781f8598) , you can click ctrl+o and choose link to import this collection

**Note:** In newman you can pass the environment variable as “ — env-var tag=Regression”

---

<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:** [February 22, 2021, 9:24am UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/2 "2021-02-22T09:24:58Z")

</div>

Looks Interesting @praveendvd. Will try this out 😊

Thanks for sharing!!

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [February 22, 2021, 12:11pm UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/3 "2021-02-22T12:11:44Z")

</div>

Thank you @bpricilla let me know your thoughts 🙂

---

<div class="post-metadata">

**Author:** ![aviation-geoscienti6](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@aviation-geoscienti6](https://community.postman.com/u/aviation-geoscienti6)\
**Post date:** [November 8, 2021, 8:56am UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/4 "2021-11-08T08:56:32Z")

</div>

Is it possible to do the same but with Folders? i.e. only run certain folders in collection that contain the word ‘Copy’

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [November 8, 2021, 9:17am UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/5 "2021-11-08T09:17:56Z")

</div>

You can use the same logic , and make some modification

---

<div class="post-metadata">

**Author:** ![julian-nadar](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@julian-nadar](https://community.postman.com/u/julian-nadar)\
**Post date:** [January 7, 2022, 6:51am UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/6 "2022-01-07T06:51:52Z")

</div>

Hi Thanks for this information. @praveendvd  
can you suggest a solution while trying to execute request with tags which is in a collection with different folder structure.  
For eg

Collection name

> Folder1  
> – req1[tag]  
> –req2  
> Folder2  
> –req1  
> –req2[tag].

Here i need to execute req1 from folder1 and req2 from folder2 inside a collection using tag

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 24, 2022, 9:09am UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/7 "2022-01-24T09:09:24Z")

</div>

Could you check the collection example . It does the same thing i believe

---

<div class="post-metadata">

**Author:** ![SRIDZQ44](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@SRIDZQ44](https://community.postman.com/u/SRIDZQ44)\
**Post date:** [April 26, 2022, 2:52pm UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/8 "2022-04-26T14:52:16Z")

</div>

Adding tag is IMP for my project, here is my requirement : Currently collection running in team city  
I need to update the results in Jira for each execution

for ex : 1 test cycle : 3 test cases automatically update from Team city to jira,

any idea how we can achieve this ?

---

<div class="post-metadata">

**Author:** ![tyson1986](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@tyson1986](https://community.postman.com/u/tyson1986)\
**Post date:** [March 27, 2023, 6:39am UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/9 "2023-03-27T06:39:11Z")

</div>

Could someone share the script for the same thing but with folders? The logic is the same, but with folders in folders in folders … it doesn’t work. Unfortunately I’m not an expert in JS, so I wasn’t able to write a function, that creates plain array of requests IDs from the tree that Postman API returns.

---

<div class="post-metadata">

**Author:** ![xxldoctor](https://avatars.discourse-cdn.com/v4/letter/x/858c86/32.png) [@xxldoctor](https://community.postman.com/u/xxldoctor)\
**Post date:** [April 24, 2023, 12:07pm UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/10 "2023-04-24T12:07:26Z")

</div>

@praveendvd Thanks, this works great, but I cant understand how to apply same logic for request in folders. Can you make an examle?

---

<div class="post-metadata">

**Author:** ![xxldoctor](https://avatars.discourse-cdn.com/v4/letter/x/858c86/32.png) [@xxldoctor](https://community.postman.com/u/xxldoctor)\
**Post date:** [April 24, 2023, 7:45pm UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/11 "2023-04-24T19:45:34Z")

</div>

I made ugly solution for folders:

```auto
let requests = [];
reqeustlist = _getRequests(pm.response.json().collection.item, requests)

function _getRequests(items, requests) {
    items.forEach(function(item) {
        if (item.hasOwnProperty("item")) {
            _getRequests(item.item, requests);
        } else {
            requests.push(item.name);
        }
    });
    return requests
}

```

@tyson1986 @julian-nadar FYI

---

<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, 2:46pm UTC](https://community.postman.com/t/how-to-run-postman-requests-using-tags/20628/12 "2024-12-12T14:46:55Z")

</div>

Closed on December 12, 2024, 2:46pm UTC

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