How to add a variable to a Rest Message's Content field dynamically?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 04:00 AM
I've a rest message function defined with some default variables:
So via script, I can substitute those values
var rm = new sn_ws.RESTMessageV2('dummyAPI', 'post');
rm.setStringParameter('callback_url', 'xxxxxxxx');
rm.setStringParameter('correlationId', 'yyyyyyy');
But is it possible to add an extra variable and substitute it on the fly? Something like below:
rm.setStringParameter('new_variable', 'abc');
I tried with the above code, but in the scripted rest API resource, when I did
gs.log(JSON.stringify(request.body.data));
I could only see "callbackUrl" and "correlationId" keys and not "new_variable".
Is there way to have that added? I don't want to update the rest message's "Content" field and would like to have that extra variable added by script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 04:29 AM
In what scenario would you need an extra variable added. Surely the request body would be pre-defined with mandatory / mandatory values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 04:36 AM
Dev vs Prod. When triggering in dev environment, I need to add an extra variable for aiding quick testing but when it's pushed to prod the variable is not required. I can simply use instance_name sys_property to know which environment the code is running in. But the only thing I need to know if it's possible to do this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 05:12 AM
I'd probably just create separate REST messages. One for Prod, the other non Prod. Then you can call whichever one you want based on the instance_name.
var env = gs.getProperty('instance_name');
var restMessage = env == 'prod' ? 'dummyAPIProd' : 'dummyAPINonProd';
var rm = new sn_ws.RESTMessageV2(restMessage, 'post');
rm.setStringParameter('callback_url', 'xxxxxxxx');
rm.setStringParameter('correlationId', 'yyyyyyy');
if(env == 'prod')
rm.setStringParameter('new_variable', 'abc');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 05:44 AM
Yes, this is a solution that we had already considered. But your answers seem to suggest I cannot do this via script?