REST not working on instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2015 04:27 PM
I'm looking at moving an application that I wrote to integrate Nagios with Service Now using Python from SOAP to REST and have run into a bit of a stumbling block.
Basically, going by the example on the SN docs, the below should work:
import requests
import json
# Set the request parameters
url = 'https://xxx.service-now.com/api/now/table/incident'
user = 'xxx'
pwd = 'xxx'
# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}
# Do the HTTP request
response = requests.post(url, auth=(user, pwd), headers=headers , data = '{"short_description": "test"}')
# Check for HTTP codes other than 200
if response.status_code != 201:
print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
raise SystemExit
# Decode the JSON response into a dictionary and use the data
print('Status:',response.status_code,'Headers:',response.headers,'Response:',response.json())But instead I get:
File "./REST.py", line 23, in print('Status:',response.status_code,'Headers:',response.headers,'Response:',response.json())
File "/usr/lib/python2.7/site-packages/requests/models.py", line 733, in json
return json.loads(self.text, **kwargs)
File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decodedI've double checked and the user account definitely has REST permissions and GET works absolutely fine. I've also tried putting all required information into the data input but it makes no difference. Also, I tried using the servicenow_rest library available from pip it seems I'm just not getting no return data.
Is this just something odd with the ServiceNow instance? Using the Chrome extension works for REST queries so guessing not?
Cheers,
Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2015 06:00 AM
Hi Allan,
Sorry for not replying on your last comment, as I was on holiday.
Do you still have an issue with the script?
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2015 06:16 AM
Hey Sergiu,
No problem at all.
Yes, it's still an issue. I had our SN guys in-house have a look but as mentioned, we've got 88 custom ACL's - so apparently they couldn't figure out why. Doesn't help that 2 of the guys working on Service Now here have left since so no progress was made.
Regards,
Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 04:45 AM
Hi Allan,
At this stage I would recommend you open an incident with ServiceNow as it needs more investigation and should be tracked via an incident.
Issue does seem to be caused by a customization rather than out of box functionality.
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 04:59 AM
Hi Sergiu,
Yep, we did that this morning. Thank you so much for your help narrowing down the problem - you've been a great help.
Regards,
Allan
