The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
shaunmillin
ServiceNow Employee
ServiceNow Employee

In this blog post we are going to dive into how to integrate 3rd party webhooks into ServiceNow. First lets talk about what a webhook is.   A webhook is a user defined http call back to an external system. Basically a webhook is a way to feed information from your application to an external system based on some event or action. Why is this important for your instance? Well if you are monitoring or discovering a custom application for CI creation or updates, this could be one use for this type of integration.

For this blog we will use github as an example, and simply echo the JSON message from github back to the system log in ServiceNow after a code commit happens.

To start we need to create a Scripted REST API.

blog 2 -1.png

Click New.

blog 2-2.png

Once the form opens fill in the Name and API ID.

blog 2-3.png

Once the Form is filled out click submit.

Now go back to the Scripted REST API's and click the one we just created.

blog 2-4.png

Scroll down to the related list area and select Resources.

blog 2-5.png

Click New.

Once you click new this will create a new Scripted REST API Resource.

blog 2-6.png

Fill in Name and then scroll down to Security.

blog 2-7.png

Clear the check box for Requires Authentication.

  • Note when you deselect Requires Authentication you are allowing unauthenticated access to this Method on your instance. Since this is a demo and an example we will not cover the security aspects of this.

Next lets change the HTTP method from GET to POST.

blog 2-8.png

Click the drop down and select POST

Now we have to tell the resource what code to run. You will see there is some example code already provided for the resource.

Default Code:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

      // implement resource here

})(request, response);

Change default to:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

gs.info(request.body.dataString);

})(request, response);

Basically we are replacing this line:

// implement resource here

With this line:

gs.info(request.body.dataString);

The default objects to work with in a Scripted REST API Resource are response and request.

For more details on request and response see here. http://geneva-docs.servicenow.com/?context=CSHelp:Scripted_REST_Request_API

http://geneva-docs.servicenow.com/?context=CSHelp:Scripted_REST_Response_API

The URL for our Scripted REST API is here.

blog 2-9.png

So the url to this resource would be https://yourInstance.service-now.com/<resource_Path>   or   https://yourInstance.service-now.com/api/snc/blogdemo

Click Submit/Update on this resource.

Now that we have created our own custom restapi we can point our application webhook at it.

Here I am going to log into my GitHub account. And create a webhook on my repository.

For instructions on how to create webhooks on github see here: https://developer.github.com/webhooks/

Inside of your GitHub repository click settings.

blog 2-10.png

On the left hand side of the screen click webhooks & services

blog 2-11.png

Then click on Add webhook.

blog 2-12.png

blog 2-13.png

The Payload URL is the resource path we created earlier.   https://yourInstance.service-now.com/api/snc/blogdemo

Once you have put in the Payload URL. Leave everything else as default and click Add webhook.

Once you have added your webhook you should see a green checkbox next to your url. This indicates that the test message was sent and github got back a successful message.

blog 2-14.png

If you did not get the green checkmark delete this webhook and review the settings we created earlier and try again.

Now go back to your instance and browse to System log -> All.

blog 2 -15.png

In the logs you should see a message like this:

blog 2 -16.png

If you see this message congratulations you have configured ServiceNow to integrate into 3rd party webhooks.

Happy Automating!

26 Comments