A Python-based SDK for ServiceNow.
- Python 3
- Clone the repository
- Switch to the local respository directory.
- Build the pip package with:
python setup.py sdist
- Install the resulting package with:
sudo pip3 install dist/servicenow-x-x-x.tar.gz
The ServiceNow module currently supports the following ServiceNow features:
sn.incident_get()
sn.incident_find()
sn.incident_task_get()
sn.incident_task_find()
sn.incident_create()
sn.major_incident_get()
sn.major_incident_find()
sn.major_incident_create()
sn.outage_get()
sn.outage_find()
sn.sc_request_get()
sn.sc_request_find()
sn.sc_request_create()
sn.sc_req_item_get()
sn.sc_req_item_find()
sn.sc_task_get()
sn.sc_task_find()
sn.sc_task_create()
sn.netgear_get()
sn.netgear_find()
sn.problem_get()
sn.problem_find()
sn.problem_create()
sn.change_request_get()
sn.change_request_find()
sn.change_request_create()
sn.change_task_get()
sn.change_task_find()
sn.change_task_create()
sn.group_get()
sn.group_find()
sn.user_get()
sn.user_find()
sn.label_entry_find()
sn.application_find()
sn.ci_get()
sn.ci_find()
sn.colo_get()
sn.colo_find()
sn.host_get()
sn.host_find()
sn.docker_engine_find()
sn.docker_container_find()
sn.docker_global_image_find()
sn.docker_local_image_find()
sn.docker_image_tag_find()
To use the module in a script you simply import it and create an instance of it.
from pprint import pprint
from servicenow.client import ServiceNow
sn = ServiceNow(
environment="dev1",
username="bob",
password="secret!",
debug=True,
)
sn.incident_get(number="INC0063436")
pprint(sn.response)
If you are familiar with ServiceNow you will understand how the queries work. If you are looking for incidents created by Bob Smith, for example, you would specify on the query string &sysparm_query=caller_id.name=Bob Smith
. Multiple queries are separarted with a carat symbol. The SDK handles all of this for you with the use of the ServiceNow Filter object.
When you create an instance of the ServiceNow module, it creates an instance of the Filter class and it can be accessed via sn.filter
methods, which will be described below in more detail. Using the above example, you can find any incidents submitted by Bob Smith using the following script.
from pprint import pprint
from servicenow.client import ServiceNow
sn = ServiceNow(
environment="dev1",
username="bob",
password="secret!",
debug=True,
)
sn.filter.add(var="caller_id.name", op="=", value="Bob Smith")
sn.incident_find()
pprint(sn.response)
Now if you want to find Bob's incidents that are in an Open
state you could add another filter.
from pprint import pprint
from servicenow.client import ServiceNow
sn = ServiceNow(
environment="dev1",
username="bob",
password="secret!",
debug=True,
)
sn.filter.add(var="caller_id.name", op="=", value="Bob Smith")
sn.filter.add(var="state", op="=", value="open")
sn.incident_find()
pprint(sn.response)
This method adds a new filter to the filter list.
This method deletes the filter with the name varname
.
This method returns the number of filters in the filter object.
This method empties the filter object, effectively initializing it as new.
- Add create methods
- Add delete methods
- Implement record limit in the constructor.
- Authors: Gary Danko