Search code examples
node.jsjsonautomationjmeterpostman

How to run thousand of json files as body of http POST request?


So there is an API that is being tested in POSTMAN. There are thousand of json files that needs to be sent as body while making POST request to the API. Is there any way in POSTMAN or any other tool or script that can make this process easier and automated. Those json files hold the resources, each json file is something like this:

{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "fullUrl": "12234",
      "resource": {
        "resourceType": "Player",
        "name": [
          {
            "family": "James",
            "given": [
              "Smith"
            ]
          }
        ],
        "gender": "male"
      },
      "request": {
        "method": "POST",
        "url": "Player"
      }
    }
}

With that post api request, there is cognito token, api key that is being sent. In short how can I loop through multiple json files and put each in request body while making POST request at API URL.


Solution

  • There is Directory Listing Config plugin which can be installed using JMeter Plugins Manager.

    You can point the plugin to the directory with your JSON files and each JMeter user will read the next JSON file on each iteration.

    enter image description here

    Once done you can use __FileToString() function in the "Body Data" tab of the HTTP Request sampler to read the current JSON file from the hard drive and set it as the request payload in JMeter

    ${__FileToString(${file},,)}
    

    enter image description here

    Demo:

    enter image description here