REST Table API Authorization Key

Abhishek Pidwa
Kilo Guru

Hi, 

I am writing a code in C# to call the servicenow Table API to retrieve the change_request rows. I am able to do this by setting Authorization to Basic with some value. It is working as expected since I took the authorization code from some other .NET application which was developed 3 years back. 

 

My question is where should I navigate to see the authorization value in ServiceNow? Where do we set this ? 

Any pointers would be great so that I can be sure that if someone changes that, I will be able to update my codebase accordingly.

 

 

1 ACCEPTED SOLUTION

i am adding one sample code here.

can you try to set like the same way.

 

 Uri sNowURI = new Uri("https://myinstance.service-now.com/api/now/table/mytable");

                               rest.BaseAddress = sNowURI;

                               rest.DefaultRequestHeaders.Authorization =

                                       new AuthenticationHeaderValue(

               "Basic",

               Convert.ToBase64String(

                       System.Text.ASCIIEncoding.ASCII.GetBytes(

                               string.Format("{0}:{1}", "user", "password"))));

                               rest.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                               HttpResponseMessage response = await rest.GetAsync(sNowURI);

                               if (response.IsSuccessStatusCode)

                               {

                                       var contents = await response.Content.ReadAsStringAsync();

                               }

 

https://community.servicenow.com/community?id=community_article&sys_id=ffcce265dbd0dbc01dcaf3231f961...

View solution in original post

7 REPLIES 7

Akash4
Kilo Sage
Kilo Sage
Go to Web Services > REST Message or SOAP Message based on your instance setup. Check in the form for User Authentication reference field. Else see at the bottom HTTP Method form. Give this a try! Regards, Akash
Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

OK so I went to REST Message and I can see some of the REST API taking Basic Auth profile into consideration. So I went ahead to that table to see how many username/password has been set . It just has these three users and that too for different applications not for Table API 

 

find_real_file.png

 

I saw a note in ServiceNow that any ITIL user credentials can perform Table API query. But my point is that how can I find that ITIL user which was used ? I don't want to use it and then later on if it gets inactivated then my REST API will fail. So if you can direct me exactly how we setup those authentication profiles that would be great. Currently my code is using some encrypted format value which is why I am unable to determine which one is it ?

 

 

I think user profile doesn't provide any information for which integration does it configured for, unless you use some meta data information.

You can try something like postman here, if this is not a production instance or if there is a chance where ServiceNow Test instance has live integration, you can make each user profile as active and others inactive at a moment and try sending REST requests if there is an authentication done to your particular URL request say https://dev2.service-now.com/api/now/v2/table/incident then that could be your perfect matching User Profile.

Let me know if this is feasible for your instance, also is this an inbound or outbound configuration from ServiceNow perspective? My solution would be for outbound from ServiceNow and Harsha's might be testing from 3rd party tool.

Regards, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Harsh Vardhan
Giga Patron

if you are accessing the  servicenow table api outside the servicenow then there should be one user which has the access in servicenow and also the validate access to perform some action on the table.

 

eg: i have used incident table and shared the table api for incident table then i will create one user which has the valid login credentials with itil role then the usr will do some action by using the table api.

 

Note: validate the user in sys_user table.