Servicenow Rest Cheat Sheet
Servicenow Rest Cheat Sheet
and test modify the data. Use the GlideRecordSecure* API in scripted RESI
Access services
Controls
Build Tests should validate the response code, headers, and body content as
Tests to appropriate for each resource you implement. You can also use tests to
verify validate authentication requirements, and to confirm that errors return
functiona useful responses.
lity
*GlideRecordSecure API Ensure that the ACLs are defined on the underlying data
are applied to the requested user.
Scripted REST APIs
API URIs This part the for the scripted rest has to define name_space,
REST Security
api_id, resource_path, version
How is REST API Secure?
API Query When defining a scripted resource, which parameter is mandatory
The REST API uses basic authentication or OAuth to enforce access controls to
Parameter for the request can also be defined
web resources. ACLs are defined on tables to restrict the data viewership.
API Error Scripted REST APIs provide multiple ways to send an error in a
Objects* response to a requesting client. Will all tables be available for the REST API Access?
By default, Yes. All tables including system tables, and scoped tables are
*Multiple error objects are available in scripted REST API scripts to report error
available.
information to requesting clients.All scripted REST API error objects use the
sn_ws_err namespace. How can I restrict a table Access through web services?
Error objects available are 400,404,406,409,415 In the table properties, uncheck the option for Allow access to this table via web
services.
REST API Best Practices
Does REST API support CORS?
Follow REST API conventions define specific behaviour for each type of
Cross Origin Resource Security is supported.
REST API method. For ex : GET : to Query the data, POST : to create
Conventions Data,PUT and PATCH : to Update data, DELETE : to delete How can I Define CORS Rules?
records. CORS Rules can be defined in sys_cors_rule. Which allows to specify a domain
and Selection of methods to expose.
Use Use versioning to implement new functionalities, so that the
Versioning existing functionalities will not impact How to disable CORS Support for Instance?
to control CORS support on instance is defined by glide.rest.cors.enabled set it to false for
changes to
No CORS
API
Return an Return a status code, which inform the requestor about the Can I use OAuth with REST?
Informative success and failures(defined in the response codes section) Yes, use OAuth token for REST Requests
HTTP
Can I use MFA with REST?
Status code
Yes again, with a REST Request, if MFA is enabled then append token to end of
Return Provide the requestor with enough information of why the failure
users password ex:userid:passwrdtoken. Encode using base64 encoding
useful error occurred. Error message is a mix of error message and error code
information
cheatography.com/bibingokuldas/
ServiceNow REST - Cheat Sheet Cheat Sheet
by Bibin Gokuldas (bibingokuldas) via cheatography.com/69673/cs/17659/
API API allows to select a specific Ex TableAPI,AggregateAPI 400 Bad The Request URI can't Invalid headers, or API
REST enables the use of few Not all the APIs available policies
Method
methods like from ServiceNow would have 404 Not Found The requested resource is ACL constraint or resource
GET,POST,DELETE ,PATCH all the methods available not found not available
Request Allows to specify a header for the Can add Custom header as 405 Method not The HTTP action is not allowed or not supported by the API
Allows to specify an encoded Can add more query 406 Not The endpoint doesn't Response format in the
Query
parameter query for the REST Call parameters or even a sys_id acceptable support the response Request Accept Header
You can prepare the sample request using the REST API Explorer in ServiceNow. 415 Unsupported The endpoint does not support the format of the request
ServiceNow REST URI looks like this <LINKFORSNOW>/api/now/apiname/. For ex : media type body.
if we are using a table API for POST then the link look something like below : POST
<LINKOFServiceNow>/api/now/table/tablename RESTMessageV2
REST API Rate Limit Sends the REST message asynchronously, that means the
executeAsync()
To prevent excessive inbound REST API requests, set rules that limit the number of instance doesn't wait for a response from provider
inbound REST API requests processed per hour.
getEndpoint() Get the URL of the endpoint for the REST message.
There is an option to create Rate Limit for users with specific roles, or for all users.
getRequestBody() Get the content of the REST message body.
The table for creating rate limit is sys_rate_limit_rules .
In the basic Response Header, the Rate limit would be specified for ex : x- getRequestHeader( Get the value for an HTTP header specified in the REST
RateLimit-Limit -->10 <headername>)* message.
getRequestHeaders Get HTTP headers that were set by the REST client and
REST API Headers () the associated values.
By design, POST, PUT, PATCH, and DELETE operations required to provide both
headers.
GET operations require only the Accept header.
There is an option override the HTTP method, such as GET or POST, by setting the
X-http-method-override header.
cheatography.com/bibingokuldas/
ServiceNow REST - Cheat Sheet Cheat Sheet
by Bibin Gokuldas (bibingokuldas) via cheatography.com/69673/cs/17659/
saveResponseBodyAsAtta Configures the REST message to save the returned setMIDServer(mids The name of the MID Server to use. Your instance must
chment(tblname,recordid,f response body as an attachment record. erver) have an active MID Server with the specified name.
ilename)**
setMutualAuth(profil Set the mutual authentication protocol profile for the REST
saveResponseBodyAsAtta Configure the REST message to save the returned ename) message.
chment(tblname,recordid,f response body as an encrypted attachment record.
setQueryParameter( Append a parameter to the end of the request URL with
ilename,encryptcontext)
name, value) the form name=value.
*
setAuthenticationProfile(ty Set the credentials for the REST message using an setRequestBody(bod Set the body content to send to the web service provider
pe,profileid) ** existing basic auth or OAuth 2.0 profile. y) when using PUT or POST HTTP methods.
Sets basic authentication headers for the REST setRequestBodyFro Sets the request body using an existing attachment
setBasicAuth(username,p
assword) message. mAttachment(attach record.
mentsysid)
setEccCorrelator(correlat Associate outbound requests and the resulting
setRequestHeader(n Set an HTTP header in the REST message to the
or) response record in the ECC queue. This method
ame,value); specified value.
only applies to REST messages sent through a MID
Server. setRequestorProfile( Override the default requestor profile for the REST
to REST messages sent through a MID Server. setStringParameter( Set a REST message function variable with the specified
setLogLevel(level) Set the log level for this message and the
*By design, this method cannot return the value for a header set automatically by the
corresponding response.Valid values for level are
system. To grant this method access to all headers, set the property
basic, elevated, and all.
glide.http.log_debug to true.
**the input parameters for this functions are string, and recordId is the sysid of the
record
cheatography.com/bibingokuldas/