Content Field in POST Call REST Message

SKum
Kilo Sage

Hello All,

 

Need help on how to pass array values into a JSON object dynamically,
Below is the post method payload format i needed
 

"Content": [
{ 
"client": "123", 
"Name":  " Name1 "
},

{ 
"client": "123", 
"Name":  “Name2 "
},

{ 
"client": "123", 
"Name":  "Name3"
}

]

In the Below REST message  content field I can only pass 1 Name, how do i pass multiple Names and clients dynamically?

 

REST Message Content Field

"Content": [
{
"Client": "${Client}",
"Name": "${Name}"
}
]

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@SKum 

you can use variable substitution and replace that in REST Message body while using script

"Content" : "${content}"

Variables in a REST Message 

then use script to form the JSON array and replace like this

Note: this is just an example; enhance it as per your requirement

var arr = [];

for (var i = 0; i < 3; i++) {
    var obj = {};
    obj['client'] = '123';
    obj['Name'] = 'Name1';
    arr.push(obj);
}

var request = new sn_ws.RESTMessageV2('name of rest message', 'name of http method');
request.setStringParameter("content", JSON.stringify(arr));
var response = request.execute();

If my response helped please mark it correct and close the thread so that it benefits future readers.

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@SKum 

you can use variable substitution and replace that in REST Message body while using script

"Content" : "${content}"

Variables in a REST Message 

then use script to form the JSON array and replace like this

Note: this is just an example; enhance it as per your requirement

var arr = [];

for (var i = 0; i < 3; i++) {
    var obj = {};
    obj['client'] = '123';
    obj['Name'] = 'Name1';
    arr.push(obj);
}

var request = new sn_ws.RESTMessageV2('name of rest message', 'name of http method');
request.setStringParameter("content", JSON.stringify(arr));
var response = request.execute();

If my response helped please mark it correct and close the thread so that it benefits future readers.

@SKum 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.