Hi, very little code experience, but use the Postman tool a lot to test our app that uses REST API Web Services.
I’m trying to set environment variables from JSON Response that are in an array.
Works fine if the Response attributes are not in an array. (2nd example)
JSON response :
“Vendors”: [
{
“VendorId”: 4515,
“AssignmentType”: “NONE”,
“LeadCounselFlag”: false,
“VendorName”: “Boston and Maine Law”,
“FirmId”: “TESTCMS-01-TEST-XYZ”,
“AssignDate”: “2019-10-31”,
“VendorType”: “LAWFIRM”,
“FeeAgreement”: “NA”,
“Designation”: “PANEL”
},
{
“VendorId”: 4671,
“AssignmentType”: “NONE”,
“LeadCounselFlag”: false,
“VendorName”: “A B & V LLP”,
“FirmId”: “113640790”,
“AssignDate”: “2019-12-31”,
“VendorType”: “LAWFIRM”,
“FeeAgreement”: “NA”,
“Designation”: “PANEL”
}
]
}
If variable is NOT in an array (only one possible value for each attribute) the following works:
JSON Response:
{
“CaseId”: 4230,
“CaseName”: “123456789JS”,
“CaseNumber”: “123456789JS”,
“CaseClass”: “Auto Injury”,
“ActiveDate”: “2019-03-09”,
“InActiveDate”: “2020-03-09”,
“CaseManagerEmpID”: “NJDELUCA”,
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable(“CaseId”, data[0].CaseId);
postman.setEnvironmentVariable(“CaseName”, data[0].CaseName);
postman.setEnvironmentVariable(“CaseNumber”, data[0].CaseNumber);
postman.setEnvironmentVariable(“CaseClass”, data[0].CaseClass);
postman.setEnvironmentVariable(“ActiveDate”, data[0].ActiveDate);
postman.setEnvironmentVariable(“InActiveDate”, data[0].InActiveDate);
postman.setEnvironmentVariable(“CaseManagerEmpID”, data[0].CaseManagerEmpID);
postman.setEnvironmentVariable(“CaseId”, data[0].CaseId);
Thank you in advance!