Dynamically change the REST message end point URL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2022 06:57 AM
Hi Experts,
We have a requirement to initiate REST call. For a catalog item, when user inputs the data and submit the request. System should pick the value and insert into the REST message end point and initiate the REST call.
Would require experts help on this requirement.
Thanks, Jay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2022 07:29 AM
Hi,
Don't create any REST Message.
You can directly invoke it from script using setEndPoint() method
1) use GlideAjax and send the value of variable and then use something like this
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('Your Value');
request.setHttpMethod('POST');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody('{"u_catalog_item":"Blackberry",' +
'"u_variables":"original^299-999-9991|' +
'replacement^Yes"}');
var response = request.execute();
gs.log(response.getBody());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2022 02:49 AM
Hi Ankur,
Thanks for quick response, as per your solution, when user's submit the request there could be many REST records created. We would like to have only one REST call that can be used dynamically for all the user requests.
Thanks, Jay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2022 09:02 PM
Hi
Here we are not creating any Rest Message in Rest Message table.
We are dynamically invoking the endpoint. So you need not worry on that.
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2023 02:21 AM
I am having similar requirement, need to pass dynamic URL whenever record gets created.
Token, project ID(6167) will be dynamic for each and every change request. How can I pass the URL in request.setEndpoint('Your Value');
Please guide