Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman - Collection.json - How to make multiple requests by passing an array? (every item in the array will be a query string value for each request)

Below is my json file for the postman collection I have. I would need to make about 100 individual requests and test the response code for each of them. The only thing that would be different in each request is the query string parameter UserID.

So, I have an array that looks something like

var users = [123, 124, 125, 126];

I would like to pass this array into the collection, so I don't have to create individual 'item' objects for every request. Is there a way to do this? I think 'variables' would be a good place for this, but I'm not sure how it works. I will be happy with a solution that uses Postman UI as well.

I can write a little console app or some javascript snippet to achieve the same, but wanted to see if it's possible via postman as I enjoy using it.

{
    "variables": [],
    "info": {
        "name": "Test a Set of Users",
        "_postman_id": "postman-guid-id",
        "description": "",
        "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
    },
    "item": [
        {
            "name": "User1",            
            "event": [
                {
                    "listen": "test",
                    "script": {
                        "type": "text/javascript",
                        "exec": "tests[\"Status code is 200\"] = responseCode.code === 200;"
                    }
                }
            ],
            "request": {
                "url": "http://localhost/myAPI/getSomething?UserId=123&isActive=true",
                "method": "GET",
                "header": [
                    {
                        "key": "Accept",
                        "value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8,,application/json",
                        "description": ""
                    },  

                    //all my other request headers - they are the same for all requests

                ],
                "body": {
                    "mode": "formdata",
                    "formdata": []
                },
                "description": ""
            },
            "response": []
        },
        "item": [
        {
            "name": "User2" // everything same as above except for the querystring Parameter UserId     
        }

     ]


}
like image 608
Ren Avatar asked Dec 07 '25 06:12

Ren


1 Answers

You can achieve this via the Collection Runner and passing your data in as CSV or JSON file.

https://learning.postman.com/docs/running-collections/working-with-data-files/

like image 173
Christian Baumann Avatar answered Dec 08 '25 18:12

Christian Baumann