0

I have bunch of requests in my postman collection for example :- Request 1 Request 2 ... Request N

For each of these requests , I want to pass a client id for which is unique per request. I have created a data file with those client ids. So the data in CSV file is as follows : - Client Id 1 2 .. N

My requirement is to use Client ID 1 in Request 1 , Client ID 2 in Request 2 instead of iterating Client ID 1 though the entire collection.

So basically data in CSV file to be used row wise in all the requests.

Would really appreciate suggestions on how this can be achieved.

I tried using Runner but it doesn't fit my requirement

Sjain
  • 69
  • 1
  • 13

1 Answers1

0

Maybe it would be easier not to use .csv file here, but Postman Environment Variables.

If you're having the number of ClientIDs matches the number of request, you can do something like this:

In the Pre-Request Script of first request you have to initiate an array of clientIDs:

const clientIdArr =  [1,2,3,4,5,6,7,8,9,10];
pm.environment.set('clientIdArr', clientIdArr);

Then we will shift the first value of array of clientID in every subsequent Postman Collection request:

const currentArr = pm.environment.get('clientIdArr');
const currentValue = currentArr.shift();
pm.environment.set('clientIdArr', currentArr);
pm.environment.set('currentClientId', currentValue);

Then you can use {{currentClientId}} environment variable in your actual request and exectute the Postman Collection via Collection Runner.

For more details how Array.prototype.shift() works please refer to the following link.

If you have a large amount of requests in your Postman Collection you might consider having those scripts as Postman Global Functions.

n-verbitsky
  • 552
  • 2
  • 9
  • 20