Using a POST request with body data imported from a CSV file in Postman
You could achieve this by using the {{...}}
syntax in the POST request body like this:
{
"groupCode": "FAFCE",
"associationCode": "",
"programTypeCode": "NE",
"rateCalculationFilters": [
{
"fieldName": "EquipmentModel",
"fieldValue": {{EquipmentModel}}
},
{
"fieldName": "TERM",
"fieldValue": {{TERM}}
},
{
"fieldName": "POWERUPRATE",
"fieldValue": {{POWERUPRATE}}
}
]
}
And then creating a CSV or a JSON file to populate these placeholders during the 11 requests.
This is an example using a JSON data file, on each iteration run it will use each set of values from the file:
[
{
"EquipmentModel": 1,
"TERM": 1,
"POWERUPRATE": 1
},
{
"EquipmentModel": 2,
"TERM": 2,
"POWERUPRATE": 2
}
]
Lalit
Updated on June 05, 2022Comments
-
Lalit almost 2 years
I am new to POSTMAN and facing an issue with driving data from an external source like a CSV file and using this to pass in data to the request body, rather than writing the same script multiple times with different sets of data.
In the request body, I am passing in raw data as (application/json)
{ "groupCode": "FAFCE", "associationCode": "", "programTypeCode": "NE", "rateCalculationFilters": [ { "fieldName": "EquipmentModel", "fieldValue": "0" //<Ex different set of data:2009,1992 > }, { "fieldName": "TERM", "fieldValue": "3" //<Ex 3,7,4 > }, { "fieldName": "POWERUPRATE", "fieldValue": "75000" //<Ex set of data:82009,77992 } ] }
I wrote 11 calls for 11 sets of data. When the data will increase, I have to write more calls & maintenance will be more than my Expectation. I want to pass data from a CSV file and run same script for number times, with different sets of data, rather than an individual script.
-
Danny Dainton about 6 yearsHave you actually tried reading the Postman documentation or their blog? blog.getpostman.com/2014/10/28/…
-
Lalit about 6 yearsYes I have gone through the article and followed the steps. The script fails and says " "A non-empty request body is required.". But with " Here is the screen short
-
Lalit about 6 yearsWith manual run and with mapping in csv file from There was an error running your collection: Invalid URL "xxxxxxxx". Where as works fine with mentioned raw JSON format
-
Danny Dainton about 6 yearsUpdate your question with all the details about what you have and haven't done so far. Also add any scripts that you're using. This is be better than trying to half explain in the comments.
-
Lalit about 6 yearsIn body, I am passing raw data as (application/json) "rateCalculationFilters": [ { "fieldName": "EquipmentModel", "fieldValue": "0" Ex different set of data:2009,1992 }, {"fieldName": "TERM", "fieldValue": "3" Ex:2,7 }, {"fieldName": "POWERUPRATE", "fieldValue": "75000" 4000, 90000 } ] Wrote 11 calls for 11 set of data. when data will increase, have to write more calls & maintenance will be more Expectation: I want to pass data from csv file & run same script for number times with different set of data, rather than individual script
-
Danny Dainton about 6 years"Update your question with all the details"
-
Lalit about 6 yearsUpdated the question, please take a look
-
-
Lalit about 6 yearsThank you, applied the logic you provided and it is working fine with CSV file now. But tried with same in JSON, but it run only one time, not picking the same set of data.
-
Danny Dainton about 6 yearsHow many
iterations
did you set? The default is1
so if you just pressed the button it would only pick up the first set of data. -
Lalit about 6 yearsThanks Danny, you are right. With JSON we have to give no of iteration . Where as with CSV iteration picks automatically, number of records csv file has
-
Lalit about 6 yearsFacing similar issue, while verify the result with variables Here is verification script pm.test("Matching interest rate 4.29", function () { pm.expect(pm.response.text()).to.include("4.29"); }); Now I want to check the result in "Test", same way as passing variable. Here is the code I tried pm.test("Matching interest rate 4.29", function () { pm.expect(pm.response.text()).to.include(data["ExpectedResult"]); }); When I see PREVIEW DATA in collection runner, it shows 4.29. It fetches the data, but result shows failed. Can you help me out to solve this issue.
-
Danny Dainton about 6 yearsThis is another question. Try not to ask multiple question in the same question - Create another one with the new details.
-
Lalit about 6 yearsCreate another question. Here is the link stackoverflow.com/questions/49277397/…
-
Rocky4Ever almost 4 yearsTried {{}} but i see my collection is not taking from file.Still has {{lastName}} itself not replaced with values from file.