Batch/ Bulk requests via Postman - WITHOUT setting request profile and variables

Dear all,

I am looking for the way I can send batch requests via Postman. I found plenty of articles in the internet about how to send batch requests via Postman. But all of them implied creating a request where all the values of the Body parameters are dynamic. It is suggested to use Postman Collection Runner, to upload a JSON/CSV file when running the collection which will contain an array of the values for each request.

But this doesn’t really correspond to my needs. I would like to be able to upload a file (JSON) which will be an array of several elements (elements not necessary identical in terms of the profile) and I need the Postman to split this array into the elements and to send each element separately to the same end-point. So I am basically ready to compose each request including the values manually, but I want to avoid sending each request manually via Postman. So I would like to upload 1 big JSON array containing dozens of this request and Postman just needs to split this array into elements and to send them consequently to the request end-point.

Could you please advise if that is possible.

Thank you in advance,

With kind regards,

Olga

The following steps should achieve what you are asking for, but you still need to use the Collection Runner.

Add the JSON as a single entry in a CSV file. Enclose it in quotes so it gets treated as a string.

It needs to be an array for this to work properly.

The pre-request script will need to parse that string which you then need to store as a collection variable.

You need to JSON.stringify it when storing it, and JSON.parse it when retrieving (or it will just get treated as a string).

Now you have the array stored as a collection variable. You are going to use a JavaScript method called array.shift.

This will retrieve the first element from the array and then delete it.
This will create a new variable that you can now use for the current request.

If the request needs a JSON body, then you can do something similar to the following.

const body = JSON.parse(pm.request.body.raw);
// do something with the existing body.
// you can create a completely new body at this point if you wanted.  Using the variable created from array.shift.
pm.request.body.raw = body;  // this is what will be used in the actual request

You now need to re-save the updated array back to the collection variable. (Remember to stringify)

In the Tests tab of the request after the request has run, you will retrieve the array again (remembering to parse).

You don’t do anything with the array, apart from check the length. You now need an IF statement that will look at the length of the array, and if its over 0, you will use a Postman function called setNextRequest() to keep rerunning the same request until the array = 0. (This feature only works in the Collection Runner).

This should loop through your JSON.

Hi Mike, thank you so much for your assistance! You brought me to the idea of using Pre-req. At the end I made it look like this:
pm.variables.set(‘body’,JSON.stringify(pm.iterationData.get(‘payload’)))

And every element of the uploaded JSON array is wrapped into payload