# How to send a request multiple times with different data?

**URL:** <https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157>\
**Category:** Help Hub\
**Tags:** multiple, tests, collections, request, pre-request\
**Created:** [March 3, 2020, 5:29pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157 "2020-03-03T17:29:34Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![anna.tirshenko](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@anna.tirshenko](https://community.postman.com/u/anna.tirshenko)\
**Post date:** [March 3, 2020, 5:29pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/1 "2020-03-03T17:29:34Z")

</div>

Hello everyone!

I want to have a collection which will contain a request. I want that request to be sent 3 times when running with Postman runner and each time with different data.  
This is my example, but when I run with runner it only posts the first data , the other two are not posted.

Request - Method: **POST**

`{{url}}/album/items`

**Body:**

`{ "item_id": "{{clipart_id}}", "item_type": "clipart" }`

**Pre-Request Scripts**

```
    var clipArtIds = pm.environment.get("clipArtIds");

        clipArtIds = ["320778942558211", "320825615368211", "320768867352211"]

    var currentClipArtId = clipArtIds.shift();
    pm.environment.set("clipArt_id", currentClipArtId);
    pm.environment.set("clipArtIds", clipArtIds);

```

**Tests**

```
var clipArtIds = pm.environment.get("clipArtIds");

if (clipArtIds && clipArtIds.length > 0) {
    postman.setNextRequest("{{url}}/albums/items");
} else {
    postman.setNextRequest(null);
}

```

So, when sending just one request that 3 items should be posted in the album after that It should stop in order to run the next separated request in the collection.  
How can I solve this ?

---

<div class="post-metadata">

**Author:** ![john-paul](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/john-paul/32/919_2.png) [@john-paul](https://community.postman.com/u/john-paul)\
**Post date:** [March 3, 2020, 11:34pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/2 "2020-03-03T23:34:48Z")

</div>

Hi @anna.tirshenko!

What jumps out at me is you’re getting clipArtIds from the environment, but then you’re overwriting that with a different array.

```auto
var clipArtIds = pm.environment.get("clipArtIds");

// remove the line below
        clipArtIds = ["320778942558211", "320825615368211", "320768867352211"]

```

What if you remove the second line in the pre-request script? Does it work?

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [March 5, 2020, 11:05pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/3 "2020-03-05T23:05:26Z")

</div>

Hi @anna.tirshenko,

You may want to look at using `JSON.stringify(clipArtIds)` when storing the array and `JSON.parse(clipArtIds)` upon retrieval.

Also, it looks like there might be a typo in your request body syntax. You’re storing the individual ID as `clipArt_id`, not `clipart_id`.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![simakanja](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/simakanja/32/5547_2.png) [@simakanja](https://community.postman.com/u/simakanja)\
**Post date:** [September 11, 2020, 8:04am UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/4 "2020-09-11T08:04:02Z")

</div>

Hi!  
I am trying to implement the same logic: I have a Post request and a list of different parameter values to be send. But it isn’t working, only first request is being sent and postman.setNextRequest doesn’t send anything at all.  
The code schema is pretty simple for such case but no idea why it is not working.  
Please, give more fresh ideas!

**POST {{url}}/locale/setRegion**

**Body**

```
{
    "params": {
        "country": "russia",
        "city": "{{currentCity}}"
    }
}

```

**Pre-request Script**

```
var cities = pm.environment.get('cities');
    if (!cities) {
        cities = ['moscow', 'saint_petersburg', 'kazan', 'rostov_on_don',

                       'nizhny_novgorod', 'krasnodar', 'sochi', 'simferopol', 'samara',

                       'novosibirsk', 'kaliningrad', 'ekaterinburg', 'ufa', 'voronezh', 'chelyabinsk', 'krasnoyarsk', 'perm', 'kursk', 'omsk', 'barnaul']
    }

    var currentCity = cities.shift();
    pm.environment.set('currentCity', currentCity);
    pm.environment.set('russianCities', cities);

```

**Tests**

```
var cities = pm.environment.get("russianCities");

if (cities && cities.length > 0){
      postman.setNextRequest("{{url}}/locale/setRegion");
}else{   
      postman.setNextRequest(null);
}
```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 11, 2020, 10:16am UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/5 "2020-09-11T10:16:29Z")

</div>

Hey @simakanja

Welcome to the community! 👋

Can you share what you have so far, it will make it easier for people to suggest possible solutions.

---

<div class="post-metadata">

**Author:** ![simakanja](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/simakanja/32/5547_2.png) [@simakanja](https://community.postman.com/u/simakanja)\
**Post date:** [September 11, 2020, 11:29am UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/6 "2020-09-11T11:29:08Z")

</div>

Hi @dannydainton ! Thanks! 🙃  
Updated my above message with code.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 11, 2020, 11:47am UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/7 "2020-09-11T11:47:18Z")

</div>

> [@simakanja](#):
>
> `postman.setNextRequest("{{url}}/locale/setRegion");`

Is “{{url}}/locale/setRegion” the name of the request?

Would this get you past sending the first request?

```auto
postman.setNextRequest(pm.info.requestName);

```

---

<div class="post-metadata">

**Author:** ![simakanja](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/simakanja/32/5547_2.png) [@simakanja](https://community.postman.com/u/simakanja)\
**Post date:** [September 11, 2020, 12:25pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/8 "2020-09-11T12:25:58Z")

</div>

> [@danny-dainton](#):
>
> `postman.setNextRequest(pm.info.requestName)`

Pardon, not quite right code  
in **Tests** I grab the {{url}} from the environment variables and concatenate like this:

```
var url = pm.environment.get("my_url")
postman.setNextRequest(url + "/locale/setRegion");

```

And this url equals to the url in the very first request.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 11, 2020, 12:52pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/9 "2020-09-11T12:52:01Z")

</div>

Is that the name of the request?

I understand that it’s going to a specific URL but the `sendNextRequest` should equal a request name `string`, rather than a URL location.

---

<div class="post-metadata">

**Author:** ![simakanja](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/simakanja/32/5547_2.png) [@simakanja](https://community.postman.com/u/simakanja)\
**Post date:** [September 11, 2020, 12:59pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/10 "2020-09-11T12:59:13Z")

</div>

@dannydainton, Got it, but I also tried it in vain: putting the full request string to pm.setNextRequest(). No effect.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 11, 2020, 1:12pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/11 "2020-09-11T13:12:59Z")

</div>

I can’t see what you can see so you might need to show an image of this. 😁

Ensure that after making any change to the request, you’re saving the change as the runner wouldn’t know about this until you do that.

---

<div class="post-metadata">

**Author:** ![simakanja](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/simakanja/32/5547_2.png) [@simakanja](https://community.postman.com/u/simakanja)\
**Post date:** [September 11, 2020, 1:25pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/12 "2020-09-11T13:25:45Z")

</div>

@danny-dainton Okay, I’ll paste screenshots here. =) By the way I do save my script before running

 ![body](https://us1.discourse-cdn.com/getpostman/original/3X/4/c/4c425e2154eb7853ea9d79291a0e1f1fedbe8e87.png) ![prereq](https://us1.discourse-cdn.com/getpostman/original/3X/e/7/e796f0ed0c9619d7d973cc1124ea1087d850ac0c.png) ![tests](https://us1.discourse-cdn.com/getpostman/original/3X/c/f/cfbd398c32ba134be16b5ed0428f2d456357bca4.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 11, 2020, 1:29pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/13 "2020-09-11T13:29:37Z")

</div>

What’s the output of the Collection Runner?

---

<div class="post-metadata">

**Author:** ![simakanja](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/simakanja/32/5547_2.png) [@simakanja](https://community.postman.com/u/simakanja)\
**Post date:** [September 11, 2020, 1:31pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/14 "2020-09-11T13:31:09Z")

</div>

@dannydainton Here, only one request.

 ![Screenshot_1](https://us1.discourse-cdn.com/getpostman/original/3X/0/6/06c46da8339c937013de0dc79b8cfe5a527c3923.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 11, 2020, 1:46pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/15 "2020-09-11T13:46:55Z")

</div>

The request is called `set_russian_city` that’s what needs to be in the `postman.setNextRequest()` function.

```auto
postman.setNextRequest("set_russian_city")

```

Or this to add that without hardcoding the string.

```auto
postman.setNextRequest(pm.info.requestName)

```

---

<div class="post-metadata">

**Author:** ![simakanja](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/simakanja/32/5547_2.png) [@simakanja](https://community.postman.com/u/simakanja)\
**Post date:** [September 11, 2020, 1:58pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/16 "2020-09-11T13:58:18Z")

</div>

@danny-dainton Oh, my Goodness, it works.  
Big thanks for your help!

---

<div class="post-metadata">

**Author:** ![aakash.narang1992](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@aakash.narang1992](https://community.postman.com/u/aakash.narang1992)\
**Post date:** [August 9, 2021, 6:17pm UTC](https://community.postman.com/t/how-to-send-a-request-multiple-times-with-different-data/11157/17 "2021-08-09T18:17:17Z")

</div>

it would be a great help if someone can help me with this, we want to add multiple user

Body  
{ “user\_name”: “{{user\_name}}”, “email”: “{{email}}” , user\_role: “underwriter”}

userName= [“user01”, “user02”, “user03”]  
email= [“email01”, "email02, “email03”]

We want to use user01 and email01 for 1st request  
user02 and email02 for 2nd request  
user03 and email03 for 3rd request

@simakanja
