How to pass multiple requests [JSON] from local folder?

I have a body requests, 500+, which I need to pass through an API and save a result. How do I pass that many request and save request and response?

Note: All those body requests are located on my desktop under folder called “Data”.
Also, not all requests have similar length, they can very but structure is same, defined below. If it helps, I don’t need to modify any data within my data set, I am just looking for a way to submit it through API.

Request Body 1 Sample:

{
  "data": {
    "d_id": "did1"
    "d_type": "dtype1"
  },
  "points": [
    {
        "testabc": {},
         "test": "test"
}
}

Request Body Sample 2:

{
  "data": {
    "d_id": "did1"
    "d_type": "dtype1"
  },
  "points": [
    {
        "testabc": {},
         "test": "test"
},
        "testabc": {},
         "test": "test"
}

Hi @jay_dave8, welcome to the community! :wave:

There’s no direct way to pass the body to a request inside Postman.

I can think of one way to get this thing working:

  1. Write a script (probaby a nodeJS script or any scripting language you’re comfortable with) to move all the request bodies from all the files into one file as an array of JSON, this file can be directly used inside the collection-runner in Postman to run each request body for a given endpoint.

For eg:
A file called data.json

[
  // Request body 1
  {
    "data": {...},
     "points": {...}
  },

  // Request body 2
  {
    "data": {...},
     "points": {...}
  }
   // ....
]

Next, you can read the following on how you can use this JSON object in the collection runner to make sure it’s correctly sent:

Following the above post, your request would look something like this:
image

Now, you should be able to hit all those 500+ endpoints.


Now, since you wanted to write the response of each request, you can follow the following post to write the responses to a file.

Note: Since your request will have the same name everytime, when writing the responses to the same file, the responses will get overwritten.

You can make the change to the script like so:

// The data to be written to file
let dataToFile = {
    requestName: `${request.name || request.url}-${pm.info.iteration}`, // Add this
    fileExtension: 'json',
    responseData: pm.response.text()
};

I know this is a bit complex, but this is all I can think of right now.

Maybe other people in the community have a better solution to it! :smiley:

1 Like