Integration means connecting ServiceNow with another application (like Workday, Jira, SAP, or any external system) so they can send and receive data automatically.
Example:
2 . REST Integration:
REST (Representational State Transfer) is a way for systems to communicate over the internet using HTTP methods like GET (read), POST (create), PUT (update), and DELETE (delete).
2.1 Type Of Rest Integration:
Representational state transfer or REST is the most popular approach of building APIs. When a request for data is sent to a REST API, it’s usually done through hypertext transfer protocol (HTTP). Once a request is received, APIs designed for REST can return messages in a variety of formats: HTML, XML, plain text, and JSON.
A request is made up of four things:
3.1 The Endpoint
The endpoint is the url you request for. It generally consists of a base path and resource path. E.g.
https://dev124645.service-now.com/api/now/table/incident
Every web service provider will have the API documentation, and that needs to be referenced in order to configure the HTTP method endpoint.
3.2 The Methods
HTTP methods define the action to take for a resource, such as retrieving information or updating a record. The available HTTP Methods are:
3.2.1. POST: Create
The POST method is used to submit the information to the server.
3.2.2. GET: Read
The GET method is the most common of all the request methods. It is used to fetch the desired resource from the server.
3.2.3. PUT: Update
Both PUT and PATCH are used to modify the resources on the server with a slight difference. PUT is a method of modifying resources where the client sends data that updates the entire resource.
3.2.3. PATCH: Update
PATCH is a method of modifying resources where the client sends partial data that is to be updated without modifying the entire data.
3.2.4. DELETE: Delete
The DELETE method is used to delete the resource identified by the request url.
3.2.5. Difference Between PUT and PATCH
Feature | PUT | PATCH |
Primary Goal | Replace the entire resource. | Update specific fields (partial update). |
Payload | Requires the complete record. | Requires only the changed fields. |
Missing Fields | Traditionally sets missing fields to NULL or default. | Leaves missing fields untouched. |
Record Creation | Can create a record if the sys_id doesn’t exist. | Fails (404 Error) if the record doesn’t exist. |
Idempotency | Idempotent: Multiple identical requests have the same effect. | Not always idempotent: Repeated calls could lead to different results. |
3.3 HTTP Headers:
Client and Server can pass the extra bit of information with the request and response using HTTP headers. The Server determines which headers are supported or required.
The most widely used HTTP Headers are:
1.Accept
Type of data client can understand.
2.Content-Type
Specifies the media type of the resource.
3.4 Authorization:
To communicate with other applications or the target application, we need entry pass, means we need some key or credentials.
In ServiceNow we need Credentials (Username and Password). So, for that source instance need credentials of Target instance user. In ServiceNow we create user with rest_service role and share those details with source instance.
3.4.1 Types of Authentication:
3.4.1.1 Basic Authentication:
Basic Authentication is a straightforward, built-in HTTP protocol feature that works as follows:
3.4.1.2 OAuth 2.0:
OAuth 2.0 is an industry-standard authorization framework (not an authentication protocol by itself, but used within them via OpenID Connect) designed for secure access delegation.
4.Use Case
Integrate two ServiceNow instance. Every time when incident is created in one ServiceNow instance (source) then incident record with same information will also get created in another ServiceNow instance (target).
So the solution we will implement to achieve is that we will create rest message and Business rule in ServiceNow source instance and below are the required information which we need from Target instance or ServiceNow target instance, which will be needed while creating the rest message.
4.1 Overall Flow (High Level)
4.2 Source Instance
Step 1: Create REST Message (Source Instance)
Navigated to:
System Web Services → Outbound → REST Message
Authentication Configuration:
This allows the source instance to securely communicate with the target instance.
Step 2: Create HTTP Method (POST)
https://dev224187.service-now.com/api/now/table/incident
Why POST?
Authentication:
Step 3: Configure Variable Substitutions
Variable | Meaning | Source Field |
cd | Caller ID | current.caller_id |
sd | Short description | current.short_description |
Why variables are important:
Step 4: Create Business Rule (Trigger Point)
Business Rule Details:
Step 5: Business Rule Script Explanation (Line by Line)
(function executeRule(current, previous /*null when async*/) {
try {
var r = new sn_ws.RESTMessageV2(‘Sample’, ‘Sample’);
🔹 Creates an object of REST Message
🔹 Refers to:
r.setStringParameterNoEscape(‘cd’, current.caller_id);
r.setStringParameterNoEscape(‘sd’,current.short_description);
🔹 Passes dynamic incident data
🔹 Maps incident fields to REST variables
var response = r.execute();
🔹 Executes the REST call
🔹 Sends data to the target instance
var responseBody = response.getBody();
gs.log(‘response:’ + responseBody);
🔹 Captures response from target instance
🔹 Logs it for debugging
var httpStatus = response.getStatusCode();
🔹 Captures HTTP status:
} catch (ex) {
var message = ex.message;
}
})(current, previous);
🔹 Error handling block
🔹 Prevents Business Rule failure
Step 6: Incident Creation (Source Instance)
What happens here:
4.3 Target Instance:
Step 7: Incident Created in Target Instance
Final Result:
Source Instance:
Source instance incident description updated with target instance incident details.
HTTP status codes are three-digit responses from a server to a client’s request, indicating whether a specific HTTP request has been successfully completed. They are grouped into five distinct classes based on the first digit.
The server has received the request and is continuing the process.
The request was successfully received, understood, and accepted.
Further action needs to be taken by the user agent to complete the request.
The request contains bad syntax or cannot be fulfilled.
The server failed to fulfill an apparently valid request.