Run collections using imported data

Run your collections in Postman using custom data for each iteration. In the Collection Runner, select the CSV or JSON file with the data you want to use. When you run the collection, Postman uses data from the file to populate variables in the collection's requests.

Data file format

Format the CSV file so that the first row has the variable names you want to use inside the requests. After that, every row will be used as a data row. The line endings of the CSV file must be in Unix format. Each row must have the same number of columns.

CSV format

For CSV files, note the following:

  • If the numbers in your data file are longer than 15 digits, you'll need to format them as text in your spreadsheet program, so they're not truncated when exporting to CSV format.

  • If your CSV file has numbers longer than 16 digits, numbers with preceding zeroes (for example, 000000345), or phone numbers (for example, +12125556709), you'll need to preview the file and specify the column type. Learn how in the next section.

Format JSON files as an array of key-value pairs. Each key is the name of a variable, and the value is the data to use within the request.

JSON format

Variable names are case sensitive, so make sure to use the same case for variables in Postman as in the CSV or JSON file. Variables in data files are resolved as local variables, so you can access them using pm.variables.get("variable_key"). Learn more about using variables in scripts.

Run a collection with data files

Suppose you have a collection with a request that accepts a serial and contact number as query parameters and a test to validate if the variable value is true.

Suppose the serial numbers in your data file contain preceding zeroes and the contact numbers have a country prefix with the + symbol.

In this example, you will create a collection, write a test for variable values, and import a CSV file into the Collection Runner. You will preview the file, specify any column types if necessary, and run the collection. Then, you will inspect your log to ensure your data was parsed correctly.

  1. Select Collections in the sidebar and select + to add a new collection. Name the collection CSV Data Types.

  2. Add a GET request with the following address. Name it Query Serial.

    https://www.xcorp.io?serial={{serial}}&contact_no={{contact_no}}
    

    The query parameters get populated with serial and contact_no keys and variable values.

  3. On the request's Scripts > Post-response tab, add the following script to test the variable values:

     pm.test('Variable should be true', () => {
         const variableValue = pm.variables.get('value');
    
         if (variableValue === true) {
             console.log('Value is true')
         } else if (variableValue === false) {
             console.log('Value is false')
         } else {
             console.log('Value is neither true or false')
         }
         pm.expect(variableValue).to.be.true
     });
    

    See the Postman JavaScript reference for more on what you can do with iteration data.

  4. Create a test CSV file as shown below. Name it test.csv.

    serial,value,name,contact_no
    0001,true,Sunny,+14155553535
    0002,false,4545,+16785553509
    0003,true,Vicky,+12125556709
    
  5. Return to the CSV Data Types collection overview and select Runner icon Run.

  6. Select your data file using the Select File button. Postman automatically sets Iterations to the number of data rows in the file.

    Data file select
  7. Select Preview to inspect the data in the file before you start the run.

    Data file preview

    Observe that the preceding zeroes in the serial number and the prefix in the contact number have been removed. Change the data type for those numbers to String to preserve the original values.

    Data file update
  8. Select Run CSV Data Types to start the collection run using the values from the data file. The Collection Runner runs all requests in the collection for each iteration (row) in the data file. The output shows the results for any tests you defined in your requests.

  9. Inspect the Console log by selecting Console in the footer, and observe that both the values and the variable validation are correct.

    Console log

Errors when reading data files

You may encounter errors when Postman attempts to read your data file during a collection run. If this happens, make sure your file is properly formatted. For guidance, see Date file format.

If the errors persist, contact the Postman support team.

Last modified: 2024/09/10