Setting HTTP Body during runtime

@spullabhotla
So, here is a sample code i use for a given API:

WS.comment("Setup")
reqUrl = "${GlobalVariable.proto}://${GlobalVariable.Url}/${GlobalVariable.Endp}"
jsonTemplate = new File(path/to/BodyFile).text

bindings = [ 'id': CampaignId, 'sTerm': SearchTerm, 'prdId': ProductId, 'token': Token ]
engine = new groovy.text.SimpleTemplateEngine()
reqBody = engine.createTemplate(jsonTemplate).make(bindings).toString()

and the template is stored as a text file, looks like:

{
"campaignId":"${id}",
"searchTerm":"${sTerm}",
"productId":${prdId},
"token":"${token}"
}

the ‘varName’ variables in bindings = [] correspond to the ${varName} in the template.

the values passed to the bindings are variables declared in the variables tab (SearchTerm and so on)

so … comparing to your code, you can try like this (notice that I am using SimpleTemplateEngine, not the Streaming one and also I call the toString() method an the end):

jsonTemplate = """{"_id": "${id}", "to": "${to}", "launch": true}"""
bindings = [ 'id' : someVariable1, 'to' : someVariable2 ]

engine = new groovy.text.SimpleTemplateEngine()
reqBody = engine.createTemplate(jsonTemplate).make(bindings).toString()

-----
request = findTestObject(‘Object Repository/external (SendGrid)/LaunchCampaign.ContentJSON(url,body,token)’, [ (‘url’) : requestUrl, (‘body’) : reqBody , (‘token’) : adminToken ])