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

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Chavan AP
Giga Guru

Jira Cloud Software Integration with ServiceNow using Webhook 

Prerequisite:

  1. Jira Cloud Software administrator Access
  2. ServiceNow instance administrator Access 

Use Case:  Whenever a Jira issue created/updated in Jira cloud software it should create a record in ServiceNow.

find_real_file.png

Follow below steps:

  1. Create custom application/table in ServiceNow with below fields 

Table Name: Jira Staging Table | u_jira_stage

Fileds:

Project Key | u_project_key

Project Name | u_project_name

Issue Key | u_issue_key

Issue Id | u_issue_id

Summary | u_summary

Description | u_description

Refer: https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/table-administrat...

find_real_file.png

2.Create Scripted REST API 

Create a scripted REST API resource to define the HTTP method, the processing script

Before you begin 

Role required: web_service_admin

About this task

By default, any new Scripted REST API resource you create contains an ACL that prohibits users with the snc_external role from making requests to the API. 

Procedure

  1. Navigate to System Web ServicesScripted REST APIs.
  2. Select a scripted REST API record.
  3. In the Resources related list, click New.
  4. Enter a Name.

The resource name affects the URI for sending requests to the API.

find_real_file.png

  1. Select the HTTP method this resource implements, In our case its POST.

find_real_file.png

 

6. In the Script field, define how the operation parses and responds to requests.

Copy below code and paste in Script:

 

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

	try { 		
	//gs.log("Jiralog "+JSON.stringify(request.body.data));
	var requestBody = request.body.data;
	
	// read the request boy and map with staging table fileds and creat/update a issue record
	gs.log('jiralog '+ requestBody.issue.fields.project.name);
	
	var jr= new GlideRecord('u_jira_stage');
	jr.addQuery('u_issue_id',requestBody.issue.id);
	jr.addQuery('u_project_key',requestBody.issue.fields.project.key);
	jr.query();
	if(!jr.next())
	{		
	
	jr.initialize();
	jr.u_project_name = requestBody.issue.fields.project.name;
	jr.u_project_key = requestBody.issue.fields.project.key;
	jr.u_issue_id = requestBody.issue.id;
	jr.u_issue_key = requestBody.issue.key;
	jr.u_summary= requestBody.issue.fields.summary;
	jr.u_description=requestBody.issue.fields.description;
	jr.insert();
	gs.log('Jira Issue created: '+jr.u_issue_id);
	}
	
	else{
	
	jr.u_summary= requestBody.issue.fields.summary;
	jr.u_description=requestBody.issue.fields.description;
	jr.update();
	gs.log('Jira Issue updated: '+jr.u_issue_id);
		
	}

 }
catch(ex) {
 var message = ex.message;
}


})(request, response);

7.Click Submit.

 

3. Create an API token

Create an API token from your Atlassian account:

  1. Log in to https://id.atlassian.com/manage/api-tokens.
  2. Click Create API token.
  3. From the dialog that appears, enter a memorable and concise Labelfor your token and click Create.
  4. Click Copy to clipboard, then paste the token to your script, or elsewhere to save:

find_real_file.png

Note:

  • For security reasons it isn't possible to view the token after closing the creation dialog; if necessary, create a new token.
  • You should store the token securely, just as for any password.

 

Refer: https://confluence.atlassian.com/cloud/api-tokens-938839638.html

 

4.Create a Jira User in ServiceNow

Username: Jira login email Id

Password: API Token

 find_real_file.png

Refer: https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/users-and-groups/...

 

5. Registering a webhook

What is webhook?

A webhook is a user-defined callback over HTTP. You can use Jira webhooks to notify your app or web application when certain events occur in Jira. For example, you might want to alert your remote application when an issue is updated or when sprint is started. Using a webhook to do this means that your remote application doesn't have to periodically poll Jira (via the REST APIs) to determine whether changes have occurred.

 

To register a webhook, you can use any of the following methods:

  • Jira administration console.
  • Jira REST API (note that the user must have the Jira Administrators global permission).

 

Registering a webhook via the Jira administration console

  1. Go to Jira administration console > SystemWebhooks (in the Advanced section).
    You can also use the quick search (keyboard shortcut is .), then type 'webhooks'. 
  2. Click Create a webhook.
  3. In the form that is shown, enter the details for your new webhook. For more information on this, see Configuring a webhook later on this page.
  4. To register your webhook, click Create.

find_real_file.png 

 

In our scenario:

Name: ServiceNow Listener
URL: https://dev102311.service-now.com/api/122636/jiratosnow
Events: Issue Updated, Issue Created

 find_real_file.png

Refer: https://developer.atlassian.com/server/jira/platform/webhooks

 

That’s all, now you can login to Jira and test the configuration.

Let’s create an issue:

find_real_file.png

 

Now login to ServiceNow and check if the issue got created in Jira staging table

find_real_file.png

 

In case of queries feel free drop your comment on the article.

If you like this article please mark it helpful !!

Regards,

Aj

+91-9769949577

https://www.linkedin.com/in/ajay-chavan-profile

 

 

Comments
Ajaykumar4
Giga Explorer

Hi AjayChavn

my name is Ajay I have a query

is it a bi-directional integration concept? 

 

Vivektietsood
Tera Guru
Tera Guru

Thanks for sharing the steps. It's a very nice and detailed article. One question - is it possible to get JIRA dev environment like we get servicenow developer instance ? Thanks again 

VaranAwesomenow
Kilo Sage
Kilo Sage

Yes, you can get free instance

Free - Jira Software | Atlassian

Snow31
Kilo Explorer

Hello,

where and how do you manage authentication to ServiceNow ?

Thank you

Prateek5
Tera Contributor

Hi Ajay,

It is not working for me. Could you help me on this.

Thanks

oharel
Kilo Sage

Hi Ajay,

Thanks for the post.

I configured everything on both sides. I am able to create a record on the staging table in our Dev instance, which means that at least on the instance side, things are configured properly. However, nothing seems to come from Jira's side. The webhook is configured correctly, as far as I can tell from your post and from atlassian documentation (Webhooks (atlassian.com))

Any ideas on how to troubleshoot are welcome.

harel

Geetha9
Tera Contributor

This does not works when authentication is checked in Scripted rest api ,any idea how we can maintain authentication in servicenow 

Samarth Chadda
Tera Contributor

Hi Ajay,

It is not working for me. Could you help me on this.

Thanks

VaranAwesomenow
Kilo Sage
Kilo Sage

In order to implement authentication you have to get creative. You need to share a key as url parameter and validate that as part of scripted API, since there was no provision to provide user name and password in jira webhook we need to take this workaround.

Maareeswari R1
Tera Contributor

Hi  Chavan,

From the above mentioned  script where you have used GET methods to retrive data's from Jira to Snow, i can see you are mapping the fileds in Jira stage table and insering that record in jira stage table via ServiceNow scripted rest message.
could you please tell me detaily how it will work for ServiceNow inbound integration?

Version history
Last update:
‎07-27-2020 05:48 AM
Updated by: