Need assisstance with creation of user in basic authentication
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 08:52 PM - edited 11-12-2023 08:54 PM
Hi All,
I am trying to create tiny url, is it possible to convert tiny url without creating an user for authentication, Currently I am hardcoading the username and password in script, it is working fine, I m searching a way where we don't need to create user to convert long URL into tiny url. I tried rest message also but there also in authentication I need to create user for basic auth profile.
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://' + gs.getProperty('instance_name') + '.service-now.com/api/now/tinyurl');
request.setHttpMethod('POST');
var user = "test.user";
var password = "123456";
var body = {};
body.url = 'http://chart.apis.google.com/chart?chs=500x500&chma=0,0,100,100&cht=p&chco=FF0000%2CFFFF00%7CFF8000%2C00FF00%7C00FF00%2C0000FF&chd=t%3A122%2C42%2C17%2C10%2C8%2C7%2C7%2C7%2C7%2C6%2C6%2C6%2C6%2C5%2C5&chl=122%7C42%7C17%7C10%7C8%7C7%7C7%7C7%7C7%7C6%7C6%7C6%7C6%7C5%7C5&chdl=android%7Cjava%7Cstack-trace%7Cbroadcastreceiver%7Candroidndk%7Cuseragent%7Candroidwebview%7Cwebview%7Cbackground%7Cmultithreading%7Candroidsource%7Csms%7Cadb%7Csollections%7Cactivity|Chart' [ChartLink]'; //url that need to be shortened
request.setBasicAuth(user, password);
//request.setAuthenticationProfile('basic', 'f7e78aab1b927d90a34b4047bc4bcbb5'); //basic auth profile
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestBody(JSON.stringify(body));
var response = request.execute();
var jsonString = response.getBody(); // get JSON of url
gs.info('Tiny URL is: ' + jsonString);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 10:58 PM
Hi @Community Alums ,
When creating tiny URLs through a service that demands authentication and doesn't support an anonymous or public API, credentials become essential for access. In such cases, opting for API keys presents a more secure alternative to directly using a username and password in your script.
Store user name and password of rest message in system property and call in rest message.
Please mark it as helpful and solution proposed if its serves your purpose.
Thanks,
Anand