How to run postman requests using Tags

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}}

to get uuid and api key goto :

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:

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

Image for post

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

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:

Ran only reqeusts that has “Copy” in its name

Example collection:

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”

3 Likes

Looks Interesting @praveendvd. Will try this out :blush:

Thanks for sharing!!

1 Like

Thank you @bpricilla let me know your thoughts :slight_smile: