Search code examples
javacsvjmeterperformance-testingload-testing

How to Send a CSV File as Request in Body


I'm trying to send a csv file as a request in body.

It's working fine for me in Postman. But I'm getting the below error in Jmeter.

{
   "id":32,
   "deleted":null,
   "uuid":"f5cec747-4794-4e54-9c4b-58da61f30921",
   "status":"Error",
   "csvFileName":"",
   "unsuccessfulRecords":[
      "['Not Applicable', '{\\'csvFile\\': [ErrorDetail(string=\\'The submitted data was not a file. Check the encoding type on the form.\\', code=\\'invalid\\')], \\'assets\\': [ErrorDetail(string=\\'Expected a list of items but got type \"str\".\\', code=\\'not_a_list\\')]}']"
   ],
   "successfulRecordsCount":0,
   "duplicateRecordsCount":0,
   "createdBy":"user",
   "createdAt":"2022-12-06T09:58:51.285524Z",
   "modifiedAt":"2022-12-06T09:58:51.285538Z",
   "idAllowdAt":"2022-12-06T09:58:51.285538Z",
   "idAllowListType":1
}

Below is the request i'm sending as part of Body Data. The REST Api accept these parameters, and afer that it imports the CSV file:

{
    "csvFile": "${__FileToString(D:/Users/anabeel/Downloads/Demo/Demo.csv,,)}",
    "allowlistTypeId": "1",
    "createdBy": "user",
    "assets": "['asset1', 'asset2']",
    "uuid": "${requestIndex}",
    "tags": "{'Platform Family':[{'abc123':'LinuxOS System'}]}",
    "tenantId": "abc456"
}

Content-type: application/json

It seems I'm not importing the csv file the right way. Can someone please help me as I dont have much experience working with Jmeter. I also tried using CSV Data Set Config, but it didn't worked for me.


Solution

  • If your request "working fine for me in Postman" you can just record it using JMeter's HTTP(S) Test Script Recorder.

    1. Configure JMeter for recording, the easiest option is going for Recording Template

    2. Import JMeter's certificate to Postman

      enter image description here

    3. Configure Postman to use JMeter as the proxy

      https://i.sstatic.net/iyS8j.png

    4. Copy your CSV file to bin folder of your JMeter installation

    5. Run your request in Postman

    6. JMeter will generate proper HTTP Request sampler and HTTP Header Manager

    7. Parameterize the path to the CSV file if needed

    8. Your JMeter request should be working fine now

    More information: JMeter Performance Testing: Upload and Download Scenarios