How to call Rest APIs(Table API) of service-now from client appliaction using Angularjs

saran3
Kilo Contributor

I need a help about how to access service now tables to be accessed by inbound restapi url   to be   called at   C#.net based client application to retrieve,create,update and retrieve records using ANGULARJS.

        I have issue while accessing the REST URL for the table created on my service now instance and i tried to consume that URL to make call from .net client   application using angularJS for CRUD operation.it would be great that any one   made a call from client application to Service now before then kindly help me out to resolve this, where i had tried to made call from ay application it shows a error as "XMLHttpRequest cannot load http://xxxxx.service-now.com/api/now/table/<tablename>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:55734' is therefore not allowed access." though i made recommended changes on request header as follows,which recommended for resolving this on many posts,

                            $http.defaults.headers.common['Access-Control-Allow-Origin'] = "*";

                      $http.defaults.headers.common['Access-Control-Allow-Headers'] = "X-Requested-With";

pradeepksharma

and also How to achieve or enable CORS(cross origin Resource sharing ),to make sure that client applications to access the rest apis without   an isssue.

Kindly help on this post....

3 REPLIES 3

Rushit Patel2
Tera Guru

Hi Saran,



I also tried making rest calls from angular client application to the instance. even if you include



                    $http.defaults.headers.common['Access-Control-Allow-Origin'] = "*";


                      $http.defaults.headers.common['Access-Control-Allow-Headers'] = "X-Requested-With";



lines in your client application, server has to respond with Access-Control-Allow-Origin = "*"; or your client name Access-Control-Allow-Origin = "localhost:9000";



if it does not respond with that during OPTION response i dont think you can access instance.



see below screenshot.


cors.JPG


Sever responds with Allow:GET,HEAD,etc   but it does not respond with Allow-origin.


I guess service now doesn't support CORS.


i hope it helps.



Regards,


Rushit Patel


saran3
Kilo Contributor

Hi Rushit,



Thanks for the information,i just heard about we can achieve the same by using custom   processors .



Thanks,



Saran


Mwatkins
ServiceNow Employee
ServiceNow Employee

ServiceNow supports CORS for the REST APIs, including the Table API and scripted REST web services. Other web service APIs, such as the SOAP API, do not support CORS.


CORS domain requirements


Define a CORS rule


REST API CORS support