Multiple tests with different data on the same POST request

Hi,
I have a json body with multiple variables that I’d like to update dynamically and run each test on it. I want to avoid having to create multiple POSTs for each scenario.
Body:
“Category”: “{{Organization}}”,
“Matter”: {{Matter}},
“WorkOffice”: “{{WorkOffice}}”,
“BillOffice”:{{BillOffice}}

Test1:
pm.environment.set(“Organization”, “Organization1”);
pm.environment.set(“Matter”, 0001);

let responseData=pm.response.json();
pm.test(“NOTAXOUT”, function () {
pm.expect(responseData.GroupCode).to.equal(“NOTAXOUT”);
});

Test2:
pm.environment.set(“Organization”, “Organization2”);
pm.environment.set(“Matter”, 0002);

let responseData=pm.response.json();
pm.test(“5%”, function () {
pm.expect(responseData.GroupCode).to.equal(“5.00”);
});

Thanks,

This type of activity is covered in the Postman Learning Centre.

If you are new to Postman, then I would suggest a visit to the Learning Centre.

Overview | Postman Learning Center

Including the Postman Training links under “Other Resources”.

image

I would recommend the “Galaxy APIs 101” course first as it gets you used to the application features.

Then the “Galaxy Testing and Automation” course which teaches you how to assert the responses. It includes using variables and basic examples of the collection runner\data files.

Further information on using data files can be found here.

Run collections using imported data | Postman Learning Center

Using CSV and JSON Data Files in the Postman Collection Runner | Postman Blog

The data you want to set, and the tests are the the same for both requests with the only difference being the values, so using a data file should achieve your goal.