POST response from Rest API using TinyURL

newservicenowus
Tera Guru

Hi All

 

I need some assitance trying to reslove an issue I have.

 

I have a some code that is passing data to a script include that is calling servicenow.com/api/now/tinyurl

This works fine and it returns the correct data, as in it is creating a tinyURL instead of the large URL we have. However when passing back to UI action (client) I get the following

{"result":"incident_list.do?sysparm_tiny=bCDZEY6ZdSvvBGHG1ghQbISkFipx04EN"}

 

I just cannot split the result from the required URL.

 

Any assistance appreciated.

 

Thanks

Dave

1 ACCEPTED SOLUTION

Hi @newservicenowus :

 

The result is in JSON format you need to parse it to get the result of the tiny url.

Use the below code snippet to access the value of result 

var api_res = response;
var url = JSON.parse(api_res);
alert('URL-  '+instnace+url.result);


 

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi @newservicenowus ,

 

What exactly you are expecting in the result and what are you trying to split.

Can you please provide more info so that we could help.

Thanks,

Sanjay Kumar

Hi Sanjay

I'm expecting just the last part of the URL - incident_list.do?sysparm_tiny=bCDZEY6ZdSvvBGHG1ghQbISkFipx04EN, so I can build the full tiny URL, getting the instance is fine.

function getURL(response) {        		
var instance = 'https://' + window.location.hostname + "/";
        alert('URL - ' + response);
        // var newsrc=instance + 'incident_list.do?sysparm_tiny=bCDZEY6ZdSvvBGHG1ghQbISkFipx04EN';
        url = response;
        alert('URL- ' + instance + url);

 Hardcoding the value works fine, just need the response to remove {"result":

I've tried using JSON.parse but that just gives me object object

 

Thanks

Dave

 

Hi @newservicenowus :

 

The result is in JSON format you need to parse it to get the result of the tiny url.

Use the below code snippet to access the value of result 

var api_res = response;
var url = JSON.parse(api_res);
alert('URL-  '+instnace+url.result);


 

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue

Hi @S Goutham 

 

Thank you very much.

Just missed the .result part