# How to pass array as a parameter

**URL:** <https://community.postman.com/t/how-to-pass-array-as-a-parameter/13673>\
**Category:** Help Hub\
**Tags:** postman\
**Created:** [June 25, 2020, 11:47am UTC](https://community.postman.com/t/how-to-pass-array-as-a-parameter/13673 "2020-06-25T11:47:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amygupta7](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@amygupta7](https://community.postman.com/u/amygupta7)\
**Post date:** [June 25, 2020, 11:47am UTC](https://community.postman.com/t/how-to-pass-array-as-a-parameter/13673/1 "2020-06-25T11:47:37Z")

</div>

Hi Guys,

I have created a global variable for site\_id like this :

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/0/80f279b5c0666e672776b1f9f7b9011cb3bb7e52.png)

but when i request the get in postman i only get site\_id = 1

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/5/b541c4fa4b41caca7f1dc0aa9f0b68405bc431c0.png)

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [June 25, 2020, 5:58pm UTC](https://community.postman.com/t/how-to-pass-array-as-a-parameter/13673/2 "2020-06-25T17:58:35Z")

</div>

Hi @amygupta7!

Welcome to the community! 👏

So naturally, environment variables only support one actual value. However, what you can do is make this value in a json format, and then in a pre request script make that json into a native javascript array and do whatever you please with it.

However, given the way you are trying to use your site ID in the request, you generally cannot pass an array as a URL Parameter. What you are looking to do then is make multiple requests for different site IDs.

Here I would suggest using the pre request script to fire off multiple requests with differing site IDs, combine those values then into one variable as a response, including the last request.

Or, you can use collection runner to run multiple requests with different site IDs, albeit they won’t be combined.

I am making assumptions on what you can do, as generally thats how REST services operate. Given that I don’t know anything about your web service, there may be other ways to achieve what you are looking to do.

Hope this help!

---

<div class="post-metadata">

**Author:** ![amygupta7](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@amygupta7](https://community.postman.com/u/amygupta7)\
**Post date:** [July 4, 2020, 1:47pm UTC](https://community.postman.com/t/how-to-pass-array-as-a-parameter/13673/3 "2020-07-04T13:47:06Z")

</div>

Hi odanyl,  
Thanks so much for your reply.

In the pre request script do I have to create the array of the site\_id?

Are there any help docs for me to review to achieve this please ?

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [July 6, 2020, 12:40pm UTC](https://community.postman.com/t/how-to-pass-array-as-a-parameter/13673/4 "2020-07-06T12:40:06Z")

</div>

@amygupta7 You’re welcome!

So yes, you would create the array of site\_ids in your pre-request script. Or, if you already know these site ids ahead of time, you can place them in an environment variable in json format.

Then you can pull that variable out in your request script and iterate over it, and make a request for each site id.

Example:

(site\_ids in environment variables -\> [1, 2, 3,])

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

var rootUrl = pm.environment.get("PUBLICAPI_ROOT_URL")

site_ids.forEach({ site_id =>

pm.sendRequest({
    url: rootUrl + "/sites/" + site_id + "/readings/summary?start_date=2020-06-22&end_date=2020-06-24,
    method: "GET",
    header: {
      'Content-Type': 'application/json'  
    }
}, function (err, response) {
    
// Parse Response
var readings = response.json["readings"];

console.log(readings)
    
});

}

```

Something like this should work, though there may be some syntax errors above. In this case, it will output to console each time you make a request for a different site ID. Now you can add some code so that each time you make a request, you append the results to an array of site\_id response to get all your data in one place, but that of course depends on what your end goal is.

Here you can learn more about pre-request scripts:

[https://learning.postman.com/docs/postman/scripts/intro-to-scripts/](https://learning.postman.com/docs/postman/scripts/intro-to-scripts/)

---

<div class="post-metadata">

**Author:** ![sean.keegan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sean.keegan/32/6353_2.png) [@sean.keegan](https://community.postman.com/u/sean.keegan)\
**Post date:** [January 13, 2022, 6:51pm UTC](https://community.postman.com/t/how-to-pass-array-as-a-parameter/13673/5 "2022-01-13T18:51:51Z")

</div>

Hi @amygupta7!

Since this question is still pulling a lot of views we’ve created a collection that shows how to achieve that in the [Postman Answers public workspace](https://www.postman.com/postman/workspace/postman-answers/overview):

[https://www.postman.com/postman/workspace/postman-answers/collection/13455110-dd27f60d-747f-4b3b-896f-6b849506e63c?ctx=documentation](https://www.postman.com/postman/workspace/postman-answers/collection/13455110-dd27f60d-747f-4b3b-896f-6b849506e63c?ctx=documentation)

Fork it and see how it works by yourself!
