Getting HTTP POST Error : {"reason":null,"error":"Request JSON object for insert cannot be null."}
<p>I am getting HTTP POST error when I am trying to connect to a Service Now Instance for Change Request Automation using Python. Here is the script I am using with Python 3.4.4</p>

<pre><code># SNOW CR AUTOMATION SCRIPT
import requests

import json

# put the ip address or dns of your SNOW API in this url
url = 'http://&lt;&gt;/change_request.do?JSONv2&amp;sysparm_action=insert'


data= {
    'short_description': '&lt;value&gt;',
    'priority': '&lt;value&gt;',
    'reason': '&lt;value&gt;',
    'u_reason_for_change': '&lt;value&gt;',
    'u_business_driver': '&lt;value&gt;',
    'u_plan_of_record_id': '&lt;value&gt;'
      }

print ("Data Inserted :")
print (data)

#Content type must be included in the header
header = {"Authorization":"Basic V1NfRVRPX1ROOkBiY2RlNTQzMjE=","Content-   Type":"application/json"}

#Performs a POST on the specified url.
response = requests.request('POST', url, auth=("&lt;value&gt;","&lt;value&gt;"), json=data, headers=header)

print ( " Header is :  ")
print (response.headers)
print ("                                                                ")
print ( "HTTP Response is :" )
print (response)
print ("                                                                ")
print ("***********************")
print (" Output : ")
print ( response.text)
</code></pre>

<p>I am getting an error as below while running the above script.</p>

<pre><code>Output : 
{"reason":null,"error":"Request JSON object for insert cannot be null."}
</code></pre>

<p>I am not sure why this error is thrown. Can anybody please help on this ?</p>

<p>First of all in Service-Now you should always use SSL, so no http!
Second error I see in your script is how you pass your payload, you need to transform your dictionary into a JSON Object/String. And you don't need to authenticate twice, you have the basic http authentication handled by requests.post so no need for it in the header.</p>

<p>With this script it should work:</p>

<pre><code>import json
import requests

url = 'https://instancename.service-now.com/change_request.do?JSONv2'
user = 'admin'
pwd = 'admin'

# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}

payload = {
    'sysparm_action': 'insert',
    'short_description': 'test_jsonv2',
    'priority': '1'
}

# Do the HTTP request
response = requests.post(url, auth=(user, pwd), headers=headers, data=json.dumps(payload))

# Check for HTTP codes other than 200
if response.status_code != 200:
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)
</code></pre>

python rest post servicenow