Get request names in prerequest/test script from runner

hello ⁠ :slightly_smiling_face:

I’m using the eval function to set the functions I’ve created at the folder level in both the prerequest script and test script, and am reusing those functions in the individual requests for the collection runs, like this:

if(postman.__execution.cursor.position !== 0) {



the folderLevelTests are running setNextRequest for different conditions using different data for requests in the folder.

My goal, if it’s possible, is to get the name or ID of the first and last requests in the folder from the test script…or to get the requests that were selected from the collection runner (or in some other way that you’d recommend that makes more sense than my logic), so that I can add conditional logic for defining set-up data in Request 1’s pre-request script; and if it’s Request 3 setNextRequest to the first request in the next folder.

I’d like to be able to add requests between Request 1 and Request 3 and have the tests run to completion with the predefined datasets while setting the next request to the first request in the next folder.

Folder A → pre-request and test script defined and set as functions

Request 1 → call folderLevelTests

Request 2 → call folderLevelTests

Request 3 → call folderLevelTests

Folder B → same pattern as above for folder and requests

Request 4

Request 5

Thanks for reading all of this!

The only way I’m aware of to get a full list of folder names and requests is to use the Postman Collection API to pull back the information about the current Collection.

This should return a JSON response which will contain the information about that collection including folder names and request names.

Have a look at the submit requests on the “15 days of Postman” or “30 Days for Developer” challenges as they use the API to pull back the Collection to run tests against to check that the challenges have been successfully met.

You will need to setup an API key on your account for this to work, but you should be able to craft a sendRequest() script in your pre-request script to pull back the collection details and work from there.


Thanks Mike, I’m checking it out now! This is probably my last question for now: do you know if there is a way to tell which requests were selected from the collection runner in the test scripts? Not sure if I’m just being hopeful or if there’s a way to achieve this

Not that I’m aware of.

You could have a script in the tests tab that updates a collection variable with this information.

You could have the script at the folder level so it applies to all of the underlying requests.

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