Importing data files
You can use data files to pass Postman sets of values to use in a collection run. By selecting a JSON or CSV data file in the Collection Runner, you can test your requests with multiple different values as part of a single run.
When you initiate a collection run you will see an option to select a data file. Click Runner at bottom right of Postman.
Select your collection, then click Select File next to Data on the right to select your data file.
You will see an option to Preview the data in the file before starting the run.
Click Run using data files to begin the run with the values from the file.
- You can try out the steps in this page by first importing the sample collection—download and import it into Postman using the Import button at the top left.
- In the Collection Runner, choose the collection you imported. Download the sample data file and select it in the Runner also.
- Note that the sample collection contains a
POSTrequest which uses a
pathvariable in the URL. This path variable is specified in each record in the data file. The request also uses a
valuevariable in the body which is also pulled from the data file for each iteration. The example request is to the Postman Echo API, a learning resource that returns the data you send it.
The Collection Runner will run the collection requests for each iteration in the data file. The output you see will indicate the results for any tests you have defined in your collection requests.
Click a request in the Collection Runner results to see more detail on its data.
Any data you have defined in the requests will be used when the collection runs, and your request data can reference values defined in the data file.
You can reference values defined in the data file throughout your requests, however to access them in scripts, you need to use a different technique. To use values from the data file in your Tests or Pre-request Script code, use the
iterationData, which provides access to the current data file record being used to run the request.
//get the 'value' field from the data file for this request run pm.iterationData.get("value")
See the Sandbox Reference for more on what you can do with iteration data.
You may encounter errors when Postman attempts to read your data file during a collection run. If this happens, you can take the following steps.
- Ensure your data file is formatted correctly, as either CSV or JSON.
- Confirm your data file is encoded properly, by opening your data file in a text editor and saving the file in a different format.
If the errors persist, contact the Postman support team.
To continue learning to leverage collection runs, check out the following resources: