API requests in bulk with Postman

This post is also available in: Español (Spanish)

If you are in a situation where you have to call an API multiple times with a variety of data, you can consider several ways to do it. Here we are going to see how you can make bulk requests, using variables from a CSV to customise each call.

You may think that the best way to achieve your goal is to make a script from scratch, but it’s not the 90’s anymore (despite the Kermit GIF) and we have thousands of tools at our disposal that make our lives easier. We are going to use Postman, which will allow us to send thousands of requests with our own variables in just a few minutes. Postman will let us call endpoints with variables of our choice {{variableCSV}} , something like this:

https://jsonplaceholder.typicode.com/todos/{{variableCSV}}?cosa={{otraVariable}}

Let’s see how we can call that endpoint with the data from a CSV to make calls like:

 GET https://jsonplaceholder.typicode.com/todos/1?cosa=sonneiltech
 GET https://jsonplaceholder.typicode.com/todos/2?cosa=blog
 GET … 

Let’s goo

If you don’t have Postman, of course, download it.

First we have to create a request in Postman.

And we fill in the request with the data of the endpoint we want to GET, using the {{}} braces to define the variable parts of our request.

Save the request in a Collection or create a new collection.

The values {{numero}} and {{entidad}} will be filled in with the data from the CSV we will upload next.

The CSV has to be formatted as follows, with the header names matching the names we have given to the variables in our request.

To run the requests with the data we have in our CSV, let’s open the Collection Runner in our collection.

Once the Collection Runner is open, we select our CSV file with the data. Once imported, we can check the number of calls in the “Iterations” value, which will match the number of rows in our CSV. Then we can also verify that the data is correct by previewing the data with the “Preview” button.

In “Preview” we can see each iteration with the values it will have at that moment.

Once verified, we are ready to make our requests. To execute the calls, click on the “Run collection_name” button.

In our case it makes 3 requests, as we had 3 entries. We can see that the variables have been populated if we inspect each of the calls.

And that would be it!

We can add as many variables as we want, simply by adding another column to the CSV and using the column name as a variable in our Postman request.

For more detailed information on Postman’s Collection Runner, please refer to the official documentation.

I hope I have spared you some manual work, this method is perfect for when you need to make one-off requests from spreadsheets.

Rock those APIs!

Leave a Reply

Your email address will not be published.