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

Hi Sergiu,



Just tried it on my colleague' computer and get the same results.



Regards,


Allan


Allan,



May I try another POST from my side? The first one I tried was directly within same network as the instance, now I want to try from outside.



Regards,


Sergiu


Of course you can. If you want to try using the same account i'm using also please let me know and I'll send you details (obviously not publicly).



Regards


Allan


Hi Allan,



Tried just now and still works for me.


Send me by email (Sergiu.Panaite@servicenow.com) your user and I will try as well to see if there is any difference.



Regards,


Sergiu


Hi Allan,



I've reproduced the issue with the user you sent me. Seems it is related to the rights of the user. I will try on my own test instance to see if I can reproduce the issue with an user with same roles and out of box access lists.


Will update you as soon as I have done my test.



Regards,


Sergiu