Jira Integration with ServiceNow using Webhook
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.servicenow.com/community/developer-articles/jira-integration-with-servicenow-using-webhook/ta-p/2296930