- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-27-2020 05:48 AM
Jira Cloud Software Integration with ServiceNow using Webhook
Prerequisite:
- Jira Cloud Software administrator Access
- ServiceNow instance administrator Access
Use Case: Whenever a Jira issue created/updated in Jira cloud software it should create a record in ServiceNow.
Follow below steps:
- 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
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
- Navigate to System Web Services> Scripted REST APIs.
- Select a scripted REST API record.
- In the Resources related list, click New.
- Enter a Name.
The resource name affects the URI for sending requests to the API.
- Select the HTTP method this resource implements, In our case its POST.
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:
- Log in to https://id.atlassian.com/manage/api-tokens.
- Click Create API token.
- From the dialog that appears, enter a memorable and concise Labelfor your token and click Create.
- Click Copy to clipboard, then paste the token to your script, or elsewhere to save:
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
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
- Go to Jira administration console > System> Webhooks (in the Advanced section).
You can also use the quick search (keyboard shortcut is .), then type 'webhooks'. - Click Create a webhook.
- 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.
- To register your webhook, click Create.
In our scenario:
Name: ServiceNow Listener
URL: https://dev102311.service-now.com/api/122636/jiratosnow
Events: Issue Updated, Issue Created
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:
Now login to ServiceNow and check if the issue got created in Jira staging table
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
- 17,080 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi AjayChavn
my name is Ajay I have a query
is it a bi-directional integration concept?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes, you can get free instance
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
where and how do you manage authentication to ServiceNow ?
Thank you
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Ajay,
It is not working for me. Could you help me on this.
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This does not works when authentication is checked in Scripted rest api ,any idea how we can maintain authentication in servicenow
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Ajay,
It is not working for me. Could you help me on this.
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have tried this and after creating the new api token the length is to long so that it wont accept in the servicenow is there any alternative for this
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You can try using url parameter instead of hard coding it in the url.