Dynamically change the REST message end point URL

Jay N
Tera Contributor

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.

find_real_file.png

find_real_file.png

Would require experts help on this requirement.

Thanks, Jay

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Don't create any REST Message.

You can directly invoke it from script using setEndPoint() method

REST Message v2

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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

Hi @Jay N 

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

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 

I am having similar requirement, need to pass dynamic URL whenever record gets created.

https://gitlab.devops.prdroot.net/api/v4/projects/6167/trigger/pipeline?token=glptt-888af59d82e2e08e...)

 

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