Hi All,
I need help to automate the Request body of an API POST method. I am having trouble with passing variables to the request body.
/* Request Body looks like this:*/
{
“customerName” : “string”,
“customerAddress1” : “string”,
“customerAddress2” : “string”
}
My script looks like this:
// enrollmentAPI_submitenrollment from object Repository
def request = ((findTestObject(‘enrollmentAPI_submitenrollment’)) as RequestObject)
/* Capturing data from Excel sheet rows (i have a loop to increment the rows in excel but thts not relevent to the issue so not providing tht info*/
def Name= findTestData(“ExcelData-1”).getValue(“ColumnName”,1)
def Address1= findTestData(“ExcelData-1”).getValue(“ColumnAddress1”,1)
def Address2= findTestData(“ExcelData-1”).getValue(“ColumnAddress2”,1)
def CustName= “customerName: ${Name}”
def CustAdd1= “customerAddress1: ${Address1}”
def CustAdd2= “customerAddress2: ${Address2}”
String body = “{${-> CustName},${-> CustAdd1},${-> CustAdd2}}”
println(body)
But this returns a body that looks like :
{ customerName : ${Name}, customerAddress1 : ${Address1}, customerAddress2 :${Address2}}
However when i submit the request like this:
request.setBodyContent(new HttpTextBodyContent(body, ‘UTF-8’, ‘application/json’))
im receiving a 400 error saying tis a bad request.
im trying to achieve a post request body like this:
{ “customerName” : “${Name}”," customerAddress1" : “${Address1}”, “customerAddress2” :“${Address2}”}
How can i get this? how can i parametrize just the names in the body to do the automation?
Plz advise
Thanks!