I have a request body that I am setting using a Collection variable - in a Pre-Request script. I then am also marking one of the properties on that request body as a variable, like so:
var obj = {
"header": {
"initiatorId": "Test, The",
"responderId": "Just",
"messageId": "e24caae1-07fd-4785-900c-73c698065c99",
"messageTimestamp": "2020-03-25T14:38:16.198Z",
"serviceId": "Test",
},
"payload": {
"serviceControl": {
},
"intermediary": {
"firmFcaRef": "{{firmFcaRef}}"
},
"applicants": "{{applicants}}",
"interestServiced": "{{interestServiced}}",
"equityReleaseCouncilProductsOnly": true,
},
}
};
var obj1= [
{
"definition": "First Applicant",
"title": "Mr",
"forenames": "John",
"surname": "Doe",
"gender": "Male",
"dateOfBirth": "1948-07-25",
"ccjBankruptcy": false,
"healthQuestions": {
"weightKg": 98,
"heightCm": 180,
"cigarettesSmokedCountPerDay": 5,
"cigarettesSmokedDurationYears": 40,
"rollingTobaccoSmokedUnitsPerDay": 0,
"rollingTobaccoSmokedDurationYears": 0,
"hasBloodPressureRequiringMedication": true,
"sufferedFromStroke": true,
"hasAnginaRequiringMedication": false,
"hasCancerRequiringSurgeryChemotherapyRadioTherapy": true,
"hasParkinsons": "Yes Without Medication",
"hasMultipleSclerosis": "No",
"hasRetiredEarlyDueToIllHealth": true,
"sufferedFromHeartAttack": false,
"hasDiabetes": false,
"hasRespiratoryConditionRequiringMedication": false
}
}];
pm.variables.set("firmFcaRef", "000000");
pm.variables.set("applicants", JSON.stringify(obj1));
pm.environment.set("requestBody", JSON.stringify(obj));
I then have a request, in which I use {{requestBody}} variable as the request body.
My issue:
The applicants variable is populating as a string in the request when it is passed in:
How can I pass in the applicants variable to my requestBody variable without it being a string? If I try and leave off the quotes around the variable, the syntax highlighter won’t permit it: