Hi all,
I’m trying to figure out how to get the dynamic variables from the Request Body. These are the 2 samples:
1. SAMPLE - using ‘pm.request.body’
Pre-request Script:
var moment = require(‘moment’);
pm.variables.set(“genRefId”, moment().format(“YYYYMMDDHHmmssSSS”));var content = pm.request.body; <---- i used pm.request.body
console.log(content);
Request Body:
{
“referenceId”:"{{genRefId}}",
“billerCode”:“PBA”,
“billReferenceNo1”:“1234567”,
“billReferenceNo2”:"",
“amount”:“3.00”
}
I also tried this but no luck.
2. SAMPLE - using JSON
Pre-request Script:
var moment = require(‘moment’);
pm.variables.set(“genRefId”, moment().format(“YYYYMMDDHHmmssSSS”));var obj = {
“referenceId”:"{{genRefId}}",
“billerCode”:“PBAC”,
“billReferenceNo1”:“1234567”,
“billReferenceNo2”:"",
“amount”:“3.00”
};
pm.globals.set(“rawBody”, JSON.stringify(obj));
Request Body:
{{rawBody}}
Expected:
{
“referenceId”:“20191114114923123”, <— this is dynamic
“billerCode”:“PBAC”,
“billReferenceNo1”:“1234567”,
“billReferenceNo2”:"",
“amount”:“3.00”
}