Skip to content

Instantly share code, notes, and snippets.

@bryanbarnard
Last active December 5, 2019 11:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bryanbarnard/8139939 to your computer and use it in GitHub Desktop.
Save bryanbarnard/8139939 to your computer and use it in GitHub Desktop.
Sample Requests Python ServiceNow JSONv2 - GetIncidents Get multiple Incidents using JSONv2 Web Service from ServiceNow using encoded query
import requests
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",
}
auth = HTTPBasicAuth("admin", "admin")
#using an encoded query
query = "priority=1^state=1^assignment_group=8a4dde73c6112278017a6a4baf547aa7"
uri = "https://demo006.service-now.com/incident.do?JSONv2&sysparm_action=getRecords&sysparm_query=" + query
headers = {
"accept": "application/json;charset=utf-8",
"Content-Type": "application/json",
}
r = requests.get(url=uri, auth=auth, proxies=proxies, verify=False, headers=headers)
content = r.json()
print "Response Status Code: " + str(r.status_code)
print "Response JSON Content: " + str(content)
print "Response Incident Count: " + str(len(content['records']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment