Get Folder Names of a Collection


for a relatively large API test project (about 1000 requests) i need a generic way to access the folder name of any request in the test scripts. Due to the high effort hard coding the folder names manually is not an option.

I couldn’t find a way to do this. The only thing I found was how to create a collection object (, but this won’t help me unfortunately.

It is possible to get the current request name by using:

What I am looking for is something like: (I know this doesn't exist)

Has anyone any idea how to get the name of the request’s folder?

Hi @hbertsch!

Outside of creating a Collection object, there isn’t a Sandbox method for getting folder name right now (but we do have an open feature request for it)

How many folders are you dealing with? What about this:

In each folder, add a pre-request script that sets a local variable with the name of the folder. You’d have to hard-code the folder name value, but if you don’t have a ton of folders this could work:

Folder A —> Pre-request script —> pm.variables.set('folder_name','Folder A');

Then, any script in your Collection can access the current folder name by using:

When the Collection run moves to the next folder, that folder would (ideally) contain the same script, but with it’s own value.


Hi, sorry for the long delay of my response :wink: have been to vacation.
Your suggested approach did the trick for me. I have added a Pre-Requests-Script to each folder (about 20) and wrote the required info to a temp var.
In my tests I have then used it to write the folder name into the test results like this:

var folderID = pm.environment.get('folderID');
pm.test(folderID, function () {

Thank you for your input :slight_smile: However a native feature still would be great

1 Like

@hbertsch Awesome! Glad that worked for you. :slight_smile: Definitely drop a comment on the feature request if it’s something you’d like to see added.

Is there any update about this feature maybe? This would be so useful

Have you figured out a good way to make this more ‘global’? It’s SO tedious to have to do this for every single pm.test.

Come on! just make it already
I wish postman had some really good competition out there so they’ll get back to developing stuff for the users instead of changing themes every month.


Did you upvote the outstanding feature request on github?

[Feature Request] Ability to read the collection and folder names in sandbox · Issue #6926 · postmanlabs/postman-app-support · GitHub

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