REST not working on instance

allanmullan
Kilo Explorer

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 decoded

I'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

28 REPLIES 28

Allan,



With out of box access lists and a test user with roles "itil" and "rest_service" it's still working for me. I am now thinking that you have some personalized ACLs that are causing the issue.



Regards,


Sergiu


Hi Sergiu,



That's certainly possible, I've no idea what the guys set that account up with but I'll double check with them tomorrow and get them to setup the correct roles and see how I get on. I'll keep you updated.



Thanks for your help so far, it's been so helpful!!!



Regards,
Allan          


Hi Sergiu,



I confirmed this morning that the user that I'm using definitely has the 'itil' and 'rest_service' roles. So perhaps our roles aren't configured correctly?



Regards,
Allan


Hi Allan,



I was referring more to the ACLs rather than user roles.


Are there personalized ACLs on user tables (sys_user*)?


The fact that having a user with itil/rest_service on my own instance works makes me think there must be something personalized on your instance causing the issue.



Regards,


Sergiu


Hi Sergiu,



I was talking to our ServiceNow guys at the office and they say there are 88 custom ACL's on the sys_user table...


Do you have any idea what ACL might be affecting this?



Regards,


Allan