Postman Tutorial Part 42 – Create Parameterized Request by Reading Data From CSV in Postman

We have already learnt storing and accessing variables in different ways like Global variables, Environment variables, Collection variables etc in Postman. All these ways are like accessing variables from internal sources.

We may require to read data from external sources as well like csv or JSON in Postman. Not only this, it is useful to achieve data driven API automation testing as well. We will see everything in details.

We will cover how can we read data from CSV in Postman. Note here I am using term “CSV (Comma Separated Values) ” not “Excel”. There are many differences between a CSV and an Excel sheet. A CSV is a file formats that contain plain text values separated by commas. You can open any csv file in an excel as well as in a text editor. CSV is only capable of storing a single sheet in a file, without any formatting and formulas. Read more about Difference between an Excel and a CSV here.

Let’s understand a scenario:-

RestFul Booker provides an API to do booking which takes a JSON body as request to provide required details. I want all these values should come from a CSV file.

Let’s create a csv file to provide data :-

We can use an excel file and save it as csv file or we can use a text editor. Using a text editor is little difficult and confusing to create csv as a beginner. So I will suggest you to create a csv data file using excel.

There is some pattern to create a csv data file for Postman. The first row represents all variable names, and subsequent rows represent values for these variables. ( I am purposefully hiding an important term here for later understanding ). Let’s input values in excel first:-

You need to take care of number and boolean field. Add a single quote (‘) before passing value for numbers and boolean to maintain the formatting. You can notice above that value of “depositpaid” is converted to uppercase value of “true”. So to keep actual formatting add single quotes.

Now save above file as csv.

We are done now with creating csv. Second step is to parameterized request. Remember we can use csv variables in URL, headers, request , scripts etc as well. Here we are using in request body.

Using variables from csv file is same as any variable from Environment, global or collection i.e. as {{variableName}}.

Note:- If variable value is a string use put above in double quotes. If it is number of boolean , put it without double quotes. See example below:-

If we are reading data from a csv, we can not run it as a normal request by clicking on “Send” button. If we click on Send button to run above request, it will give you error “400 – Bad Request” because it will not able to get values for the variables defined. We have not told Postman where to look for values yet.

So we need to use Collection Runner for this. Save above request in a collection and launch collection runner. You can find all concepts of Collection and Collection RUnner on my blog here.

In Collection Runner, you will see a field named “Data” with “Select File”. Here you need to select csv file which we created above. Click on “Select File” button and select the csv file. You will see after selection, Data File type will automatically show as text/csv. You can preview the file.

Now run the collection by clicking on “Run <Collection Name>” button.

You will see Run result of Collection. You can see json request takes values from csv file.

You can find successful response as well:-

So we have read data from csv successfully.

You can download example csv from below link:-

You can import example collection from here:-

https://www.getpostman.com/collections/c35399b642d3e5aa591f

#ThanksForReading

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.
%d bloggers like this: