How to pass the value dynamically in REST messages endpoint
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 05:18 AM
instated of {topicName} I wanted to pass the value for example a1_topic. And using put method I need to pass the payload.
I tried with the below script
var oAuthClient = new sn_auth.GlideOAuthClient();
var params = {
'grant_type': 'client_credentials',
'client_id': 'MLW2',
'client_secret': 'gAA'
};
var json = new global.JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('EDL ', text);
var token1 = tokenResponse.getToken();
var token = token1.getAccessToken();
// var tokenParsed = JSON.parse(token);
// var token2 = tokenParsed.token;
gs.print("update existing token" + token);
var topicName="a15_topic";
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setStringParameterNoEscape("Token", token);
//restMessage.setAuthenticationProfile('oauth2', '43c1772e1b8ad9502fdb844467777');
restMessage.setHttpMethod("put");
restMessage.setEndpoint("https://api-dev.nametopic.com/data/v1/topics/{topicName}");
restMessage.setRequestBody("request_id","RITM1");
restMessage.setRequestBody("number","2");
var response = restMessage.execute();
gs.print("test" +response);
I am getting like this error
escaped absolute path not valid: java.lang.IllegalArgumentException: Invalid uri
Please any one look into this one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 05:32 AM
So I would add it in your HTTP Methods, and create one with corresponding with your action. I would honestly also have all your OAUTH done by an OAUTH profile also instead of all that custom scripting...
In your endport you write "https://api-dev.nametopic.com/data/v1/topics/${topicName}"
And under Variable substitution you add one with name "topicName" and no escaping.
so ${topicName} is what is being replaced. Se example for an azure integration using these principles.
Then in your script you don't need to provide the URL, instead you write:
var r = new sn_ws.RESTMessageV2('name_of_rest_message, 'name_of_HTTP_METHOD');
r.setStringParameterNoEscape('topicName', topicName);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
For my Azure example I would write:
var group_id = 'x';
var r = new sn_ws.RESTMessageV2('Azure AD', 'Add Members to Group');
r.setStringParameterNoEscape('group-id', group_id);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
Best regards,
Sebastian Laursen