Display variable content in Response Handling text

Take a normal Response Handling statement:

    pm.test("response is ok", function () {

I would like to customize the text with a variable coming from a Data Input File:

pm.test("response FOR CUSTOMER " + {{path}} + " is ok", function () {

In Collection Runner I open an input file that populates the variable path.
This means the variable path is undefined at the start, it is populated at run time.

My URL is:


My input file:

> path
> 4567459687
> 4357349584
> 2396504398
> 4572839495

With the first Response Handling statement (without ‘path’ in the text, see top of my post) the execution is perfect, the variable path is read from the input file, populates the URL and executes as expected.

As soon as I try to include the variable “path” to leave information in the Response Handling statement text, I get an error and the variable is displayed as undefined (only in the text, the url is still working fine)

I cannot use

> pm.environment.get("path")

since “path” is not an environment variable, it is undefined at start populated first at run time

Hi @vwsamba21w

Welcome to the community!

I think I see what your issue is here.

Have you tried accessing the variable in your script by using the “data” variable?

if you want to get the path to output, and path is a column in your data file, it looks like all you would need to do is data.path, so that your code would look like so:

pm.test("response FOR CUSTOMER " + data.path.toString() + " is ok", function () { pm.response.to.have.status(200); });

I referred to their docs here to get this.


Let us know if it worked!

— Orest

Hey @vwsamba21w

You should be able to use pm.iterationData.get('path') in the test name.

pm.test(`response FOR CUSTOMER ${pm.iterationData.get('path')} is ok`, function () {
1 Like

Ah @danny-dainton I was looking for this in the documentation as well! I knew I have seen it before, but couldn’t remember where I saw it.

Would it be possible to add this way of getting iteration data into the Learning Postman Docs?

Thanks in advance,
— Orest

You will be able to find that here :grin:


1 Like

Awesome! I have never seen this before.

Maybe a link between the two? :thinking:

The docs are all open source and we’d love you to submit a PR for that suggestion :slight_smile:

Would be a great addition. :trophy:

1 Like

Agreed! Looks like it’s time for my first PR! :blush:

1 Like

Hi odanylewycz,

This worked like a charm. THANKS A LOT! :grinning:

1 Like

Hi dannydainton,

Unfortunately I couldn’t put your suggestion to work. Thanks anyway for trying.

That’s strange :frowning: - Was there a particular error message that was returned when you tried using this? Interesting to see where it’s failing for you. :thinking:

The pm.iterationData function has been part of the app for a while now and is the best thing to use when working with data files loaded in from the Collection Runner.