- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 09:36 AM
I'm new to SNOW development, so feel free to offer any level of advice here.
My scenario is this:
I created a bunch of outbound REST messages.
Some of these REST calls accept a bunch of parameters (15+) which I added in the Query Parameters of the calls.
Currently, any call on these results in an error if I don't pass something into every single parameter.
What I need is a way to allow a call to these REST messages that'll accept an arbitrary number and combination of the parameters. How should I architect/implement this? Any advice is appreciated. Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 07:12 AM
Hi Lars,
That would work if I could give generic values to every parameter, but I can't. For example, one of the parameters is a createdOnDate in a search method. Anything I pass into here is going to cause the wrong thing to be returned if someone were searching on URL name only. What I need is a way to mix and match parameters gracefully, using only 2 or 3 for instance. My current thinking is that I'll have to pass in a key/value pair string with every option I want, parse it, and then use that set to add parameters dynamically to the call with setQueryParameter(String name, String value). Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 06:38 AM
Hi
You need to do variable substitution on each of your parameters. Then you can set the value of each parameter in the script you are calling the REST message from.
Example: A REST messages need the following JSON:
{"country":"name of country","street":"name of street"}.
In Query parameter you specity this as
{"country":"${country}","street":"${street}"}
In your script you can then set the value of each of these variables:
var r = new sn_ws.RESTMessageV2('REST message name', 'post');
r.setStringParameter('country', 'Denmark');
r.setStringParameter('street', 'Main road');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 07:12 AM
Hi Lars,
That would work if I could give generic values to every parameter, but I can't. For example, one of the parameters is a createdOnDate in a search method. Anything I pass into here is going to cause the wrong thing to be returned if someone were searching on URL name only. What I need is a way to mix and match parameters gracefully, using only 2 or 3 for instance. My current thinking is that I'll have to pass in a key/value pair string with every option I want, parse it, and then use that set to add parameters dynamically to the call with setQueryParameter(String name, String value). Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 10:32 PM
Then only have as a single variable ${query} in query parameter and nothing else in the field.
Then construct the entire JSON in the script instead.
var json = '{"country":"Denmark","street":"Main Road"}';
r.setStringParameter('query', json);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 06:15 AM
Yeah, I was afraid it would come to that. Oh well. So it goes. Thanks for weighing in, sir.