shaunmillin
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
cwjurges
Giga Contributor

Good stuff, Ben. As you know Perspectium can help too!


bryanbarnard
ServiceNow Employee

Nice article. Great example of using Scripted REST APIs to enable an integration. Curious what other systems you've seen WebHooks being exposed in?


shaunmillin
ServiceNow Employee

Well Webhooks are becoming more and more popular, as more companies/applications use them to do integrations to drive automation.



I have done custom integrations with only a few. (AWS, Jira, BitBucket, GitHub, GitLab, and Jenkins) I know there are several more tools that use them, but this is my experience in playing around doing some different integrations.


abuthahir
Tera Expert

Hi Shanu,


Thats a great article. I am trying the same and it is very successful with text. What about attachments (example: photo)?.


1. If i am trying to send an attachments from my 3rd party tool to servicenow. Where can i see those attachment.?


2. Just opposite of above, I have a third party tool where i have to send an attachment from servicenow as a "INPUT FILE" type. How can i acheive that using this scripted REST API. will i be able to get that attachment path.? Please suggest. Thanks in advance.


shantanumadane
Kilo Explorer

Hi,



I want to call my webhook when a ticket is updated on service now.


Rafa4
Kilo Contributor

Hello, 

have you found out how to do that? i am interested. if yes, please share with me.

Rohn Adams
Kilo Explorer

Team Foundation Server has WebHooks that can be used to sync changes from TFS to ServiceNow.

Rick Mann
Tera Expert

Hey Shaun

I'm working on an integration between ServiceNow and Jira using Webhooks.  I have everything working correctly, but I have a question on the Security of my Scripted REST API.  Is there a way to add any level of security to the API so that I don't have to leave it open?  I can't find a way to setup any security headers in the Jira webhook.  Thanks.

 

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.
DV3
Kilo Explorer

Hi,

I am trying to use same concept with adobe webhooks. I have setup a REST API in ServiceNow and when I add the Webhook in Adobe, it throws an error : "The URL provided is not valid Webhook URL."

 

Please let me know if I am missing something.

Thanks

Sharique Azim
Mega Sage

what is the average speed for this? and what is the capacity of sending data.