logo

NJP

Python Web Service Client Using SUDS and ServiceNow

Import · Jan 07, 2013 · article

OK. Seriously, if you are not programming in Python you need an intervention and that is what I am here for. Look I am not asking you to change your coding language preference for everything you do, but Python makes consuming a ServiceNow Web Service so very easy. If you are writing code to consume a ServiceNow web service then try it in Python using the SUDS API. Here are some examples.There are different libraries you can use for SOAP web service calls (and our Wiki uses SOAPpy - which isn't really supported anymore from the open source community I read) so I recommend using SUDS. Here is the link: https://fedorahosted.org/suds/wiki/Documentation

EXAMPLE: Consuming Directly the Incident table

from suds.client import ClientWSDL_URL = 'https://yourinstance.service-now.com/incident.do?WSDL'USERNAME = "user"PASSWORD = "password"# URL Detailclient = Client(WSDL_URL, username=USERNAME, password=PASSWORD)result = client.service.get('8d6353eac0a8016400d8a125ca14fc1f') #sysid as defined in the wsdlprint 'Number for this incident is: ' + result.numberprint 'Short Description for this incident is: ' + result.short_description

Result: an incident dictionary

Number for this incident is: INC0000007Short Description for this incident is: Need access to sales db for the west

This works for any of the WSDL defined functions.

EXAMPLE: using getKeys

from suds.client import ClientWSDL_URL = 'https://yourinstance.service-now.com/incident.do?WSDL'USERNAME = "user"PASSWORD = "password"# URL Detailclient = Client(WSDL_URL, username=USERNAME, password=PASSWORD)result = client.service.getKeys(category = 'Network')print result.sys_id

Result: a Python tuple of sys_ids

[04b1b489c0a801660075f946d6cf929c,471bfbc7a9fe198101e77a3e10e5d47f,9c573169c611228700193229fff72400,e8caedcbc0a80164017df472f39eaed1]

I know this is simple and I almost feel embarrassed sharing it, so take it for what it is worth. I love me some Python! For your reference here is the ServiceNow Wiki to our direct web service API:

http://wiki.servicenow.com/index.php?title=Direct\_Web\_Service\_API\_Functions

View original source

https://www.servicenow.com/community/in-other-news/python-web-service-client-using-suds-and-servicenow/ba-p/2276744