Passing a JSON.stringify object to RESTMessageV2 in Service Portal Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2016 10:49 AM
Hello,
I have a need to pass a JSON string to a REST API I have. I construct a normal javascript object and want to stringy it. But stringify doesn't seem to work. It does not properly encode the string:
var request_body = {"var" : "Hello World"}; var r = new sn_ws.RESTMessageV2('Testing API', 'post'); r.setStringParameter('body', JSON.stringify(request_obj));
var response = r.execute(); |
is there a limitation here?
Looking at the console logs shows as an object when I do:
console.log(JSON.stringify(request_body));
But when I concat it with "My Object:" it encodes properly.
console.log("My Object :" + JSON.stringify(request_body));
Also putting params in the Rest Message does not work because if the variable contains " (double-quote) it breaks the Json string.
Thanks,
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2016 08:50 PM
If your widget is in a Scoped Application then you will need to use global.JSON.stringify(request_obj).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 09:09 PM
I am getting an issue when I either JSON.stringify or global.JSON.stringify it converts the current.number or what ever variab;e to "variable":{} instead of "variable":"somevalue"
any ideas pls?