Skip to content

Instantly share code, notes, and snippets.

@bryanbarnard
Last active July 22, 2022 18:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bryanbarnard/8198767 to your computer and use it in GitHub Desktop.
Save bryanbarnard/8198767 to your computer and use it in GitHub Desktop.
Sample Requests Python ServiceNow JSONv2 - Create an Incident
import json
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")
uri = "https://demo006.service-now.com/incident.do?JSONv2"
# 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#insert
payload = {
'sysparm_action': 'insert',
'category': 'software',
'impact': '1',
'urgency': '1',
'short_description': 'new incident from JSONv2 API',
'cmdb_ci': 'Email',
'caller_id': 'Abel Tuter'
}
r = requests.post(url=uri, data=json.dumps(payload), auth=auth, proxies=proxies, verify=False, headers=headers)
content = r.json()
assert (r.status_code == 200)
print "Response Status Code: " + str(r.status_code)
print "Response JSON Content: " + str(content)
@anksvault
Copy link

Is there a way i could handle ADFS in between?

@RodrigoSchneiderbr
Copy link

show, i know that is a noob question, but if i want just data from yesterday, do you have a examples? Other questions to pagination i use the sysparm_offset, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment