The CSV file needs to have the variable names in its first row. Postman lets you import CSV or JSON files as data sources. Make sure to enable Chrome DevTools first. You can log values to the Chrome DevTools console inside test scripts. You can access the data values for a specific iteration using the special data variable. I have also added a couple of tests, which checks whether the correct value was received in the response. Values for these will be filled by Postman from a data file. Let’s save our request above in a collection and use data variables to change the response body.Īs shown in the screenshot above, I have added a couple of parameters to the JSON body. For every iteration, it will pick up new values from a JSON or a CSV file and replace variables in the request with these values. The Collection Runner can run a collection or a folder multiple times. This is an extremely powerful feature and I am sure you will wonder how you went by without it!ĭata variables are used inside the Collection Runner. Subsequent calls are made using these values. You can also access these values using the special environment and globals dictionaries.Ĭheck out our blog post about how you can extract values from response bodies and assign them to variables. Inside Postman test scripts, you can set environment and global variables using the tEnvironmentVariable and tGlobalVariable functions. If you still haven’t purchased it, I strongly recommend that you do!
#POSTMAN DOWNLOAD CSV FILE UPGRADE#
You will need the Jetpacks upgrade for writing test scripts.
On hitting send, we see that the API received the response body with the variable replaced by it’s value. Now, let’s modify this request by adding a POST body and setting a variable inside the body. The request will be made to localhost:5000. On hitting send here with the “Production” environment, we see that the request is made to “”.Ĭhange the environment to “dev”, and hit send. If no environment is selected, then Postman will try to find a matching global variable. Once an environment is selected, Postman will replace all instances of a variable with its corresponding value. Now select an environment from the environment selection dropdown. To use a variable you need to enclose the variable name with double curly braces – /post. Variables can be used almost everywhere inside Postman. Fill in the values, as shown in the screenshot below. To create the dev environment, we can just duplicate this environment so that we don’t have to type in variable keys all over again.Ĭlick the duplicate environment icon, and then click on the environment name to edit. Fill in the values as shown in the screenshot below. Select “Manage environments” and then on the “Add” button in the modal that comes up.ģ. Click on “No environment” in the header.Ģ.
Let’s look at how you can use variables in your workflow inside Postman.įor this example, let’s assume we want to create two environments, production and dev. Using data variables, you can test for hundreds of variations of a request with different IDs, tokens or content bodies. Imagine that you want to test an API that lets users post comments on a post. Variable values are also available inside tests to help you make them more generic.ĭata variables let you test multiple instances of a request in one go. You can chain requests one after the other with minimal effort. You can extract data from responses and set variable values automatically. With Jetpacks, you get even more power to play with variables. You can also use variables to test for different users (for example, they might need different access tokens), different input values, and a lot more. Using variables, you can call all these APIs without having to manually replace values. Using variables in your Postman requests eliminates the need to duplicate requests, which can save a lot of time!Ī very common scenario while testing APIs is that the API infrastructure might be present on your local machine, a staging setup, and a production setup. Variables are among the most powerful features in Postman. Update: If you want to learn more about variables and Postman, read our 10 Tips for Working with Postman Variables.