Introduction
Rest integration in ServiceNow is a vast topic and have infinite possibilities to integrate to virtually any third-party vendor software.Here we are going to take a look at the basic steps thats generally required irrespective of the parities involved in the integration.
Endpoint
Endpoints are references that accept request from an external system.
For example: If an external app wants to create a new incident in SNOW, then it needs to call the rest endpoint in SNOW instance.
Components of a REST call
API Explorer
API explorer is an OOTB application in SNOW where we can test the rest endpoints.
.png)
Rest methods can be
- GET
- POST
- PUT
- DELETE
- PATCH
Postman
Postman is a Rest client to test restful WebService endpoints. We will make use of Postman to test the rest endpoints in our ServiceNow instance.
Difference between inbound and outbound request
Request which are incoming to ServiceNow is inbound request.
For example: Using the rest endpoint to insert a new incident Request which are outgoing with respect to service is outbound request.
For example: Calling a third party vendor api to update the status of an incident Calling monitoring tool endpoint to collect metric data
Ways to import data in to ServiceNow
- Direct table
- Through import set
- Scripted WebServices
Secure endpoint
We can secure the endpoint by restricted access to user with rest_service role only. Then caller can pass the user name and pwd as Basic Authorization header when calling the endpoint.
.png)
Then when calling, the caller will pass this credential as Authorization header
.png)
This Authorization is combination of username:password base64 encoded from the information below
.png)
Crud Operation
Using POST method to insert into service now instance. Prepare for Insert into Incident table
Got to API Explorer and prepare the payload and other attributes
.png)
In the right side select the table where we want to import
.png)
Keep the headers as it is
.png)
Request header we need to the basic authorization header, we will add in the postman In request body ,add the attributes we want to populate, note that the explorer automatically creates the json version below
.png)
We can add other parameters like response fields we need to see, exclude reference link from the response. For now we will not add any.Now we need to go the bottom and copy the curl version of the script
.png)
Note that the user here is admin:admin because by default API explorer uses the admin account to query.When we will use postman we will use the user create earlier and pass it on as authorization header.
Now go to postman and click import.Paste the code we copied earlier.
.png)
After clicking import we can the post call is available below
.png)
Now we need add the basic authorization header
Go to Authorization header tag, change the drop down to basic auth and add the user name/pwd we create earlier
.png)
Now lets trigger the endpoint, we will see the response as below
We can see that a incident got created with number as INC001002
.png)
Now lets query this incident which using get and add additional parameters based on our needs
.png)
We select the table as incident
.png)
We can add other system parameters as queries,
Sysparm_query we can add encoded query from the filter we use in the list view
sysparm_exclude_reference_link we can exclude/include the referernce link (like opened by field)
sysparm_limit
sysparm_fields we can mention which fields we want in the response
.png)
Lets copy the query from curl script and paste in the postman again an import
We can see the parameters got added in the header as key/values
.png)
Click send to see the response
Now we can see less response.
Get a specific record
We can also query for specific record by passing the sys_Id of the record
Lets copy the script again
.png)
Example of a uni directional flow
Rest integration can either be inbound or out bound
Inbound
.png)
Outbound
.png)
In our scenario, as we don’t have a external system so we will use our ServiceNow system both as source and destination
Scenario
- Create an incident record using direct API call via postman
- Write BR that will call a rest service endpoint of staging table
- the staging table will use transform map and create record in problem table.
https://docs.ServiceNow.com/bundle/newyork-application-development/page/build/applications/concept/api-rest.html
.png)
Note: The user calling the API should have appropriate role to call the endpoint.
For example: To create a problem record, the user should have ITIL role
.png)
So we need to give itil role to the cti user
.png)
Without this role the user will get 403
.png)
Step 1 We need to check the problem table api endpoint (this will be the inbound request to ServiceNow)
.png)
We then test the endpoint using postman
.png)
Now we are going to use this api and create a outbound Rest Message (this will be outbound to ServiceNow)
.png)
Here we give the external end point(in our case it the same instance we are working) and also the basic auth profile. Next we need add the http method to create a problem record
.png)
.png)
In the content, for now hard code request body, we need to update into dynamic fields later
Then we test, and see if problem gets created successfully
Now we have to call this outbound rest message from the business rule
Lets copy the script from the related links
.png)
Now we create a new BR and the rest call code
.png)
So here we are calling the rest message and also adding the parameter “sd” which will copy the short description from the incident record to the target problem record.
We have to update the rest message also with this dynamic variable
.png)
We are all done now.
Lets create an incident using the direct table API call using postman and observe if a problem record gets created
Now we will check if problem record got created
.png)
Now lets refine the response a little bit so that we can figure out from the log the problem number
.png)
*Question: How can we update an existing record using update record api?
To update the remote system we need the remote record sys_id.
So the strategy will be as below
- Create a custom field as remote_client_id in incident table
- while creating the remote problem record, capture the sys_id from the response and set it to remote_client_id
- during the update call, use this custom field
.png)
Using import API
Instead of using direct table api to insert the problem record. We can use a staging table then refine the data and then insert into the incident table
Lets see the import staging table api structure
.png)
Create a new column description
Now we are going to insert into this staging table and then use transform to load it into the problem
.png)
Now lets create transform map
.png)
Now lets create the mapping
.png)
Now lets add this staging table to import set api in api explorer
.png)
Lets call the api and test if this populating the target problem table through the transform map
.png)
We click send
.png)
Now we check problem table and see the record inserted.
.png)
Now we need to update the outbound WebService rest message with the new endpoint(staging table)
We do insert and stay and create duplicate
.png)
Also we need to update the BR
.png)
Also note we need add the role from custom table to the CTI user
.png)
Let update the BR
.png)
Scripted WebService
Scripted WebServices gives full control of the payload incase of inbound request to ServiceNow. We can write custom script include and attach to a scripted WebService. In that case, when caller calls the scripted WebService with custom attributes, we can write advance logic in the script include before inserting/updating data into ServiceNow table
.png)
Let’s open this scripted WebService in API explorer
.png)
As a query param we pass the sysid of the user whose HR profile we want to view. We click send and get a successful response
We now create our own scripted WebService with scenario described below
Scenario
create scenario
- An external application sends post call to /create endpoint of the scripted endpoint in ServiceNow
- Internally it calls a script include
- the script include calls a glide record and insert a new incident record
- the script include returns the sysid
- the scripted WebService returns the sysid response
update scenario
- An external application sends post call to /update with the sysid received from create scneraio.
- Updates the record
- returns success/failure message
- All other flows same as create scenario
Create scenario
First let create the script include, the script need not to be client callable as we are going to call it from the scripted WebService which is server side
.png)
Now write down the script include
.png)
Now we will create the scripted WebService
.png)
This the root url, now we will add the resource
.png)
Now lets test the api
.png)
Through post man also we get success response
.png)
Also record got created in the incident table
.png)
- Understanding Request, RITM, Task in ServiceNow
- Steps to create a case in ServiceNow (CSM)
- Performance Analytics in 10 mins
- Event Management in 10 minutes - part1
- Event Management in 10 minutes - part2
- Custom Lookup List
- Script includes in 5 minutes
- Interactive Filter in 5 minutes
- UI Policy in 6 Minutes
- Client Side Script Versus Server Side Script in 3 minutes
-
Snow
- Performance Analytics
- ServiceNow Scripts
- Script include
- Useful scripts
- Basic Glide Scripts
- Client Script
- Advance Glide Script
- Glide System Script
- Admin
- Import Set
- Work Flow
- ACL
- SLA
- Notification
- Core Application
- UI Policy
- UI Action
- Client Script
- CAB Workbech
- Data Policy
- Connect Support
- Catalog
- Discovery
- CSM
- Event Management
- HR
- Integrations
- SSO Integration
- LDAP Integration
- SCCM Integration
- AWS Intergration
- Slack Integration
- CTI Integration
- Jira Integration
- Ebonding ServiceNow
- SOAP Integration
- IBM Netcool Integration
- VIP Mobile App Integration
- Rest Integration
- Service Portal
- Questions
- ACL
- Performance analytics(PA) Interactive Filter
- Various Configurations in Performance analytics(PA)
- Service Portal
- Performance Analytics(PA) Widgets
- Performance Analytics(PA) Indicator
- Performance Analytics(PA) Buckets
- Performance Analytics(PA) Automated Breakdown
- Client Script
- Rest Integration
- Understanding the Request, RITM, Task
- Service Catalogs
- Events in ServiceNow
- Advance glide script in ServiceNow
- CAB Workbench
Comments