Postman request body update on conditional basis


#1

I have a request body as below:
{
“accessInfo”: {
“serviceKey” :“gfdgfdg4545435fdgdfg”,
“endUserId”:1234567890,
“accessChannel”: “MTSMS”,
“referenceCode”: “{{randInt}}” ,
“serviceIdentifier”: “49330012001”
}}

I have to run the above API with collection runner for multiple cases. So for one case i have to pass empty string in enduser id, and in another case i have to remove this completely from the body so in prerequest script am deleting the value on conditional basis.

var reqData = JSON.parse(request.data);
if(reqData.required==0{
delete reqData.accessInfo.endUserId;
}
request.body=reqData;
request.data=reqData ;
console.log(request.data);

In console it is printing with out that element but in API request this element is appending. Can you please let me know how we can change the request body in pre request or before API process.
thanks in advance