Created
January 2, 2014 16:40
-
-
Save bryanbarnard/8222030 to your computer and use it in GitHub Desktop.
Sample Requests Python ServiceNow JSONv2 - Update an Incident
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import datetime | |
from requests.auth import HTTPBasicAuth | |
# using local http proxy to log requests and responses | |
proxies = { | |
"http": "http://127.0.0.1:8888", | |
"https": "https://127.0.0.1:8888", | |
} | |
# specify basic auth | |
auth = HTTPBasicAuth("admin", "admin") | |
# specify uri | |
uri = "https://demo006.service-now.com/incident.do?JSONv2&sysparm_query=sys_id=471d4732a9fe198100affbf655e59172" | |
# define http headers for request | |
headers = { | |
"Accept": "application/json;charset=utf-8", | |
"Content-Type": "application/json" | |
} | |
# define payload for request, note we are passing the sysparm_action variable in the body of the request | |
# http://wiki.servicenow.com/index.php?title=JSONv2_Web_Service#update | |
payload = { | |
'sysparm_action': 'update', | |
'short_description': 'incident updated via JSONv2 API at ' + str(datetime.datetime.now()) | |
} | |
# issue request | |
r = requests.post(url=uri, data=json.dumps(payload), auth=auth, proxies=proxies, verify=False, headers=headers) | |
content = r.json() | |
# evaluate response | |
assert (r.status_code == 200) | |
print "Response Status Code: " + str(r.status_code) | |
print "Response JSON Content: " + str(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment