Getting 401 Error when trying to access the records using Access-Token
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2016 10:22 PM
Hi,
I am trying to access records using rest api, but some times, not every time , i get 401 error, could you please help me to understand why i am getting 401 error.
here are the streps , what i am trying to do
1.generate Access token and refresh token and store in DB.
2. trying to access data from table using rest api [record_url="https://{}.service-now.com/api/now/table/{}?sysparm_query=sys_updated_on>={}^ORDERBY sys_updated_on]
3. if it fails or give 401 error then trying to refresh access token.
4 if still getting 401 error then exit
but most of the time above code works perfectly but some times it gives 401 error.
Could you please help me to understand why i am getting 401 error.
Note: if i don't have access then it should not generate Access token and refresh token
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2016 10:32 PM
Hi Rakesh,
It is possible that sometimes you're hitting the 401 (unauthorized error) because you're accessing specific records that you don't have access to. This security will be enforced either by ACLs or by onBefore query business rules.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2016 10:48 PM
Thanks Berny, for prompt reply.
but i am not asking for specific records, i am always send below request.
"https://my_instance.service-now.com/api/now/table/incident?sysparm_query=sys_updated_on>={}^ORDERBY sys_updated_on.
but some time it doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2016 10:59 PM
Hi Rakesh,
But the records you're requesting (the result) will always vary depending on what parameter you're passing to the query string (highlighted below as thisparameter)
t?sysparm_query=sys_updated_on>={thisparameter}^ORDERBY sys_updated_on
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2016 11:29 PM
Hi Berny,
yes, 'sys_updated_on>={thisparameter}' thisparameter will always update, i will try to explain with an example.
Suppose we have some records
id sys_updated_on (time)
id1 10
id2 11
id3 12
if i will send below request.
https://my_instance.service-now.com/api/now/table/incident?sysparm_query=sys_updated_on>=10^ORDERBY sys_updated_on.
result should be
[id1,id2,id3]
if query
if i will send below request.
https://my_instance.service-now.com/api/now/table/incident?sysparm_query=sys_updated_on>=12^ORDERBY sys_updated_on.
result should be
[id13]
if i will send below request.
https://my_instance.service-now.com/api/now/table/incident?sysparm_query=sys_updated_on>=13^ORDERBY sys_updated_on.
result should be
[]
but i am getting 401 error it is unauthorized error.
if i request for a record which doesn't exists , in this case i should get 404 error.