Outbound Rest integration in ServiceNow | ServiceNow Rest Integration

Integration between applications is quite common. In real world you will find that, mostly applications are integrated with other application is any sense. For example if you are booking flight, booking train, booking movie ticket, login functionality using google account, maps, weather details and lots of other things. Applications use others API's to display information on their platform. In ServiceNow platform it is very simple to implement ServiceNow rest integration and ServiceNow soap integration with other applications either it is Uni- Directional or Bi-Directional integration.

Here in this article we will talk about Outbound Rest Integration in ServiceNow. Here we will discuss about endpoints, methods, authorization details etc. We will cover each and every thing about ServiceNow rest integration.

As we know integration is basically a communication between two applications or in other words we can say meaning on integrating two application is that making two application talk to each other and share data with each other.

Here in this article we will integrate two ServiceNow application, One instance of ServiceNow will be treated as Source and Other instance of ServiceNow is treated as Target.
In Integration Source instance send request to Target instance and Target instance send back the response . So the concept will remain same for either we will integrate ServiceNow with any other application as well.

Below in screenshot we have mentioned some communication between two instances, so that they can integrate.

Outbound Rest Integration in ServiceNow

ServiceNow Rest Integration Example or Scenario:

Below is the scenarios which we will implement to understand the integration in ServiceNow.

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.
  1. ENDPOINTS
  2. METHODS
  3. REQUEST BODY
  4. HEADERS (CONTENT TYPE)
  5. AUTHORIZATION DETAILS
Let's understand above things in little details:

ENDPOINTS:

Endpoints are the https address where we need to send information or it is the URL which will accept the web services.
Basically endpoint is the address of the application to whom the source application wants to communicate.

METHODS:

Methods tell that what source is doing for target instance. For e.g. create records, update, delete the record etc. Methods are used to perform CRUD operations i.e. Create, Read, Update and Delete
  • GET (to retrieve the record)
  • POST (to create the record)
  • PUT (to modify the record)
  • PATCH (to update the record)
  • DELETE (to delete the record)

AUTHORIZATION:

To communicate with other application 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.

In ServiceNow we can get above information from Rest API explorer, below is the video link which will help to you to know that how we can collect all these information from ServiceNow target instance.


Please find the below script of  Business Rule (before business rule) implemented in ServiceNow source instance:

(function executeRule(current, previous /*null when async*/) {

var request = new sn_ws.RESTMessageV2('Incident Integration','incident_record_creation');
request.setStringParameterNoEscape('caller',current.caller_id);
request.setStringParameterNoEscape('short_description',current.short_description);
request.setStringParameterNoEscape('category',current.category);
request.setStringParameterNoEscape('impact',current.impact);
//request.execute();
var response=request.execute();
var requestBody=request.getRequestBody();
var responseBody=response.getBody();
var httpStatus=response.getStatusCode();
gs.log(responseBody);
responseJSON=responseBody.substring(10,responseBody.length-1);
parsedJSON=JSON.parse(responseJSON);
var targetIncidentNumber=parsedJSON['number'];
var targetIncidentsysid=parsedJSON['sys_id'];
var logString='Target Incident Number - '+targetIncidentNumber+"\nTarget Incident Sys ID - "+targetIncidentsysid;
gs.log(logString,'BR- Create Incident in Target Instance');

})(current, previous);

Please find the below HTTP Request method parameter script mentioned in Rest Message:

{
"caller_id":"${caller}",
"short_description":"${short_description}",
"category":"${category}",
"impact":"${impact}"
}

We hope all the above information we have shared related to rest integration in ServiceNow will help you understand the basics of ServiceNow rest integration and the video link we have shared above will help to know that how we can integrate two application in ServiceNow using Table API (direct webservices). Please let us know you feedback in below comments section  and also let us know if you have any query related to integration in ServiceNow. 

4 comments:

  1. Thanks so much for showing how to do this. This is really helpful!

    ReplyDelete
  2. Meaning of this line can anyone explain? responseJSON=responseBody.substring(10,responseBody.length-1)

    ReplyDelete
  3. Hi, Thank you for the video. Can you please explain how to update the record with outbond Rest integartion.

    ReplyDelete
  4. Can you please help in updating the record by Outbound Scripted Rest Api

    ReplyDelete

Thankyou !!!!

Powered by Blogger.