I want to call a external REST Service with out using the REST Message of ServiceNow. I need to call rest using client script. So the loggedin user's authuneticity should be used in for REST autorization.

chandan18
Kilo Contributor

I know calling a REST Api using REST Message API from Server Script using basic autorizaton model.

But the client specific requirement is, we should call the REST from client side (from service portal widget) and logged in user's authenticity need to be used for REST autorization.

1 ACCEPTED SOLUTION

User166992
Tera Guru

Hello Chandan,



I think below article may help you for calling Rest Service from Service Portal:



How to use a REST API with RESTMessageV2 in Service Portal.



Do let me know if that works for you.



Best Regards,


Jaikumar Haryani


View solution in original post

2 REPLIES 2

User166992
Tera Guru

Hello Chandan,



I think below article may help you for calling Rest Service from Service Portal:



How to use a REST API with RESTMessageV2 in Service Portal.



Do let me know if that works for you.



Best Regards,


Jaikumar Haryani


saptashwa_chakr
Kilo Expert

Hi Chandan,


You can add the following script in your Client script of Servicenow Portal:


function($http,$scope){


        /*Calling a Rest API*/


        var options = {


                  method: 'GET', // Get method to fetch data


                  url: 'https://httpbin.org/get',


                  headers: {


                            'Content-Type': 'application/json;charset=UTF-8'


                  }


        }


        $http(options).then(function(response){


        console.log(response);


        });


}


find_real_file.png


from data, you will get the response.


You have to give HTTPS enabled REST url. If you give "HTTP" in spite of "HTTPS" then service now will encounter an error to console. Following :


find_real_file.png



So it is necessary to use HTTPS parameter.



Thank you.


If you feel that it is a correct answer then please make it as correct. Otherwise please let me know I will look into the matter again.