Show Menu
Cheatography

ServiceNow SOAP - Cheat Sheet Cheat Sheet (DRAFT) by

SOAP API in ServiceNow

This is a draft cheat sheet. It is a work in progress and is not finished yet.

SOAP Vs Rest Basics

SOAP Structure

SOAP Envelope
It is the enclosing element of an XML message identi­fying it as a SOAP message.
SOAP Header
A collection of one or more header blocks targeted at each SOAP receiver.
SOAP Body
Contains the body of the message intended for the SOAP receiver. The interp­ret­ation and processing of SOAP body is defined by header blocks.

Authen­tic­ation Using SOAP

Basic Authen­tic­ation
Basic Authen­tic­ation can be enforced by setting a username and password for a webservice request. When the property is enabled 'glide.ba­sic­aut­h.r­equ­ired' then auth header is mandatory

SOAP Message API

execute()
Send the SOAP message to the endpoint.
execut­eAs­ync()
Send the SOAP message to the ECC queue.
getEnd­point()
Get End point of specified SOAP message
getReq­ues­tBody()
Get the content of the SOAP message body.
getReq­ues­tHe­ade­r(h­ead­ername)
Get the value for an HTTP header specified by the SOAP client.
getReq­ues­tHe­aders()
Get HTTP headers that were set by the SOAP client and the associated values.
setBas­icA­uth­(us­ern­ame­,pa­ssword)
Set basic authen­tic­ation headers for the SOAP message.
setEcc­Cor­rel­ato­r(s­tri­ngc­orr­elator)
Associate outbound requests and the resulting response record in the ECC queue. Applicable to SOAP Messages through Mid Server
setEcc­Par­ame­ter­(na­me,­value)
Override a value from the database by writing to the SOAP message payload
setEnd­poi­nt(­end­point)
Set the endpoint for the SOAP message.
setHtt­pTi­meo­ut(­mil­ise­conds)
Set the amount of time the SOAP message waits for a response from the web service provider before the request times out.
setLog­Lev­el(­level)
Sets the log level for this message and the corres­ponding response. The Values of level can be basic, elevated, all
setMID­Ser­ver­(mi­dse­rve­rname)
Configure the SOAP message to be sent through a MID Server.
setMut­ual­Aut­h(p­rof­ile­name)
Set the mutual authen­tic­ation protocol profile for the SOAP message.
setReq­ues­tBo­dy(­req­ues­tbody)
Set the body content to send to the web service provider.
setReq­ues­tHe­ade­r(h­ead­ern­ame­,he­ade­rvalue)
Set an HTTP header in the SOAP message to the specified value.
setSOA­PAc­tio­n(s­oap­action)
Define the SOAP action this SOAP message performs.
setStr­ing­Par­ame­ter­(na­me,­value)
Set a variable with the specified name from the SOAP message record to the specified value.
setStr­ing­Par­ame­ter­NoE­sca­pe(­nam­e,v­alue)
Set a variable with the specified name from the SOAP message record to the specified value, doesn't escape XML reserved chars
setWSS­ecu­rit­y(k­eys­tre­ID,­key­str­eal­ias­,ke­yst­rep­swd­,ce­rti­ficate)
Sets web service security values for the SOAP message.

Are my Questions answered?

 
 

SOAP Concepts & Termin­ology

Provider : Publishes web service for clients to invoke (consume).
Consumer : Invokes / consumes published web service.
Standards : Standards are described below
WSDL : Web Service Descri­ption Language , XML document describing functions, arguments, data schema, and endpoint (where / how to invoke the service, URL)
SOAP : Simple Object Access Protocol, XML document usually HTTP posted to web service endpoint described in WSDL SOAP:E­nvelope / SOAP:H­eader / SOAP:Body
HTTP : Hyper-Text Transfer Protocol, POST vs GET - Web Service is POSTed

Direct Webser­vices

getKeys
Query the targeted table by example values and return a comma delimited sys_id list.
Data Retrieval API
getRecords
Query the targeted table by example values and return all matching records and their fields.
Data Retrieval API
get
Query a single record from the targeted table by sys_id and return the record and its fields.
Data Retrieval API
aggregate
Query using and aggregate functions SUM, COUNT MIN, MAX and AVG. To enable the aggregate functions, activate the Aggregate Web Service Plugin.
Data Retrieval API
insert
Creates a new record for the table targeted in the URL.
Data Modifi­cation API
insert­Mul­tiple
Creates multiple new records for the table targeted in the URL. To enable multiple inserts, activate the Web Service Insert Multiple Plugin.
Data Modifi­cation API
update
Updates a existing record in the targeted table in the URL, identified by the mandatory sys_id field.
Data Modifi­cation API
delete­Record
Deletes a record from the targeted table by supplying its sys_id.
Data Modifi­cation API
delete­Mul­tiple
Delete multiple records from the targeted table by example values.
Data Modifi­cation API
The standard SOAP API is a set of globally defined functions that can be performed on a table in Servic­eNow, these functions cant be changed.

Direct Webservice API is defined by the format https:­//<­ins­tance name>.s­er­vic­e-n­ow.c­om­/<table name>.do

SOAP Response APIs

getAll­Hea­ders()
Return all headers contained in the response, including any duplicate headers.
getBody()
Get the content of the SOAP response body.
getCoo­kies()
Returns all cookies included in the response.
getErr­orC­ode()
Get the numeric error code if there was an error during the SOAP transa­cti­on.This is not Linked with the HTTP error code.
getErr­orM­ess­age()
Get the error message if there was an error during the SOAP transa­ction.
getHea­der­(name)
Get the value for a specified HTTP header.If there are duplicate headers, then it will return the last of duplicate.
getSta­tus­Code()
Get the numeric HTTP status code returned by the SOAP provider.
haveEr­ror()
Indicate if there was an error during the SOAP transa­ction.
waitFo­rRe­spo­nse­(se­conds)
Set the amount of time in seconds, the instance waits for a response from the web service provider.
The API which uses these function is SOAPRe­spo­nseV2 for ex :
var r = new sn_ws.S­OA­PMe­ssa­geV­2('­SOA­PMe­ssage, 'funct­ion');
var resp = r.exec­ute();
var hdrs = resp.g­etA­llH­ead­ers();
for(var i in hdrs){
gs.log­(hd­rs[­i].name + ': ' + hdrs[i­].v­alue);
}