Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Fail to access my dev lab instance through API (Java and Python)

Goran Pettersso
Mega Guru

Hello!

 

I have 2 lab instances:

 

1. A learning lab instance:

Work fine to access tables through REST API resquests through Safari

 

Ex: https://nowlearning-nlinstxxxxxxxxxlab.service-now.com/api/now/table/sys_hub_flow?&sysparm_exclude_r...

 
If I  change to my Dev lab instance

Works fine through Safari.

ex: https://xxxxxxxxxservice-now.com/api/now/table/sys_hub_flow?sysparm_limit=1

 

If I do the request from my code  it works fine to the learning lab instance. But if I do the same towards my dev environment i get the following error:

the request: https://devxxxxxx.service-now.com/api/now/table/sys_hub_flow?sysparm_limit=1

 

Status: 400 Headers: {'Content-Type': 'text/html;charset=utf-8', 'Content-Length': '571', 'Date': 'Sun, 18 Feb 2024 10:08:00 GMT', 'X-Cnection': 'close', 'Server': 'ServiceNow', 'Set-Cookie': 'BIGipServerpool_devxxxxx=176534794.56128.0000; path=/; Httponly; Secure; SameSite=None; Secure', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains'} Error Response: b'<html><head><title>ServiceNow - Error report</title><style><!--body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}--></style> </head><body><h1>HTTP Status 400 \xe2\x80\x93 </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception Report</p><p><b>Message</b> <u></u></p><p><b>Description</b> <u>http.400</u></p><HR size="1" noshade="noshade"><h3>ServiceNow</h3></body></html>'

 

Tried to find if there are security differences between the two lab instances.

 

I am using the same user in safari and in the code. basic authenication. 

 the learning instance is San Diego. The lab instance is Vancouver Patch 2 Hot Fix 1

 

Thanks for any help where to fix the problem!

 

Göran

 

1 ACCEPTED SOLUTION

Hello Tony!

Thanks for the respond! 

I spent 2 days try to understand the OAuth to solve the problem that way but I gave up. 

 

I solved the problem after endless tries.

In my learning lab instance I had the request get to ServiceNow table

headers = {"Accept":"application/json", "content-type}":"application/json"}
response = requests.get(urlnoparam, auth=(user, pwd), headers=headers)
The headers parameter  did not work in Vancouver!
when I took away the headers it worked fine....
response = requests.get(urlnoparam, auth=(user, pwd))
 
Wierd!!
 
 
 
 

 

 

 

 

View solution in original post

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, testing a PDI running glide-vancouver-07-06-2023__patch2-hotfix1-10-04-2023

I have no issues with a GET query using basic auth and this endpoint
/api/now/table/sys_hub_flow?sysparm_limit=1
Have you checked\confirmed that the account you are using to authenticate with has rights to access the table?

 

Hello Tony!

Thanks for the respond! 

I spent 2 days try to understand the OAuth to solve the problem that way but I gave up. 

 

I solved the problem after endless tries.

In my learning lab instance I had the request get to ServiceNow table

headers = {"Accept":"application/json", "content-type}":"application/json"}
response = requests.get(urlnoparam, auth=(user, pwd), headers=headers)
The headers parameter  did not work in Vancouver!
when I took away the headers it worked fine....
response = requests.get(urlnoparam, auth=(user, pwd))
 
Wierd!!