- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎03-11-2021 01:27 AM
- Create a scripted REST API in ServiceNow with url parameter to hold operation and issue ID.
- https://dev63486.service-now.com/api/125590/jiraintegration/{operation}/{id}
- https://dev63486.service-now.com/api/125590/jiraintegration/JiraIssueCreation/${issue.id}
- Create a webhook in Jira, select trigger as insert on issue, use scripted REST API endpoint.
- Create a Outbound REST Message to get Issue details from Jira.
- https://xxxxxx.atlassian.net/rest/api/3/issue/${issueID}
- Create incident in ServiceNow based on issue details.
Note : Scripted REST API has authentication set to not required.
In order to allow ServiceNow to access Jira API API token has to be setup on Jira side.
Jira API documentation : The Jira Cloud platform REST API (atlassian.com)
Jira API token documentation : Manage API tokens for your Atlassian account | Atlassian Support
Scripted REST API code
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var sLog = '';
var pathParams = request.pathParams;
var operation = pathParams.operation; //'myApp_table'
var issueId = pathParams.id; //'1234'
sLog += "\n operation=" + operation;
sLog += " \n id=" + issueId;
var issueDetails = '';
issueDetails = getIssueDetails(issueId);
//sLog += '\n IssueDetails=' + issueDetails;
var issueJson = JSON.parse(issueDetails);
var issueSummary = issueJson.fields.summary;
//var issueDesc = issueJson.fields.description;
var issueDesc = issueJson.fields.description.content[0].content[0].text;
//var issueDescString = JSON.stringify(issueDesc);
sLog += "\n Issue id = " + issueJson.id;
sLog += "\n Issue description = " + issueDesc;
sLog += "\n issueSummary = " + issueSummary;
gs.log(sLog, 'jiraint');
//Get Issue details from Jira and create an incident in ServiceNow
if (operation.indexOf('JiraIssueCreation') > -1) {
createIncident(issueId, issueSummary, issueDesc);
}
function createIncident(issueId, issueSummary, issueDesc) {
var grInc = new GlideRecord('incident');
grInc.initialize();
grInc.short_description = issueSummary;
grInc.description = issueDesc;
grInc.correlation_id = issueId;
grInc.correlation_display = 'jira';
grInc.insert();
}
function getIssueDetails(issueID) {
try {
var r = new sn_ws.RESTMessageV2('JiraIntegrationEndpoint', 'Get Issue Details');
// r.setStringParameterNoEscape('issueID', 'SE-23');
r.setStringParameterNoEscape('issueID', issueID);
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
return responseBody;
//return JSON.stringify(request.body.data) ; //gs.log(JSON.stringify(request.body.data));
}
})(request, response);
Youtube link : https://youtu.be/bZT1LYSIomI
- 11,878 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is good !... but would highly recommend taking a look at the Jira spoke and integrationhub. Makes life much much easier - no more writing code.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Anil,
Thanks for the Article !!
I have a question here about authentication.
Note: Scripted REST API has authentication set to not required. ( Copied from your post)--- Does this mean anyone can access this rest API if they know the URL right ?, can't we make it safe by using authentication through Jira webhook?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Dear Nikesh, Based on my understanding Jira webhook doesnt support authentication. So I have setup a workaround for this by sending a key via webhook as url parameter and that is validated in the script, if the key is incorrect I send a 4XX response.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Do you have the code that you used for this? I would be interested in seeing how you set that up.
Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
please I need more info on the Jira spoke.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Anil,
Could you please help me to send attachment to JIRA using REST?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is there anything that has been implemented?
I can't connect jira and servicenow here
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @jcordova @me2 @krishanu @wanwan and everyone else off course!
Connecting ServiceNow and Jira using these methods can be very time consuming and a hassle to setup.
A very good alternative is to use a specialised solution that provides you all the flexibility you need without all the hassle of trying to get it to work on your own.
A great solution for this is Exalate. As it is a fully decentralised solution, it allows you to connect ServiceNow to Jira and many other ITSM solutions. While allowing both systems to keep their workflows and metrics in place. It provides ways for you to decide what information you want to send from one system to another (including attachments) and full control on how this information is being received and where it gets assigned to/displayed as well.
If you have any questions please let me know.
Kind regards,
Marwan
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @VaranAwesomenow ,
I have done same as you shown in above. But ticket is not created from Jira to ServiceNow. could you help me on that. Ticket is not created from Jira to ServiceNow instance. Done the same step. Please check below screenshot.
//var sLog = '';
var pathParams = request.pathParams;
var operation = pathParams.operation; //'myApp_table'
var issueId = pathParams.id; //'1234'
var req = request.body.data;
var webhookevent = req.webhookEvent;
var sLog = '';
sLog += "\n operation=" + operation;
sLog += " \n id=" + issueId;
var issueDetails = '';
issueDetails = getIssueDetails(issueId);
//sLog += '\n IssueDetails=' + issueDetails;
var issueJson = JSON.parse(issueDetails);
var issueSummary = issueJson.fields.summary;
//var issueDesc = issueJson.fields.description;
var issueDesc = issueJson.fields.description.content[0].content[0].text;
//var issueDescString = JSON.stringify(issueDesc);
sLog += "\n Issue id = " + issueJson.id;
sLog += "\n Issue description = " + issueDesc;
sLog += "\n issueSummary = " + issueSummary;
gs.log(sLog, 'jiraint');
//Get Issue details from Jira and create an incident in ServiceNow
if (operation.indexOf('JiraIssueCreation') > -1) {
createIncident(issueId, issueSummary, issueDesc);
}
function createIncident(issueId, issueSummary, issueDesc) {
var grInc = new GlideRecord('incident');
grInc.initialize();
grInc.short_description = issueSummary;
grInc.description = issueDesc;
grInc.correlation_id = issueId;
grInc.correlation_display = 'jira';
grInc.insert();
}
function getIssueDetails(issueID) {
try {
var r = new sn_ws.RESTMessageV2('testing jira external', 'Get Issue details');
// r.setStringParameterNoEscape('issueID', 'SE-23');
r.setStringParameterNoEscape('issueID', issueId);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
return responseBody;
//return JSON.stringify(request.body.data) ; //gs.log(JSON.stringify(request.body.data));
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
I have one doubt here,
How "JiraIssueCreation" comes in below end point?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@SasiKiranG I believe its a url parameter to identify the operation so that scripted REST API can perform the next steps, it available in scripted REST API code provided in the post.