Skip to content

Add JIRA REST API message script to create JIRA Task #1089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions RESTMessageV2/Jira/createJiraTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// JIRA REST API Endpoint
var jiraEndpoint = 'https://your-jira-instance.atlassian.net/rest/api/latest/issue';

// Authentication
var user = '[email protected]';
var token = 'your_api_token';
var auth = 'Basic ' + gs.base64Encode(user + ':' + token); // Scoped Base64 Encode
// var auth = 'Basic ' + GlideStringUtil.base64Encode(user + ':' + token); // Global Base64 Encode


// JIRA Payload
var requestBody = {
"fields": {
"project": {
"key": "PROJECT_KEY" // Project Key in JIRA
},
"summary": "Task Summary",
"description": "Task Description",
"issuetype": {
"name": "Task" // Issue type
}
}
};

// REST API Call
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('POST');
request.setEndpoint(jiraEndpoint);
request.setRequestHeader('Authorization', auth);
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestBody(JSON.stringify(requestBody));

// Execute the request
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

// Log response for debugging
gs.info('JIRA Response Status: ' + httpStatus);
gs.info('JIRA Response Body: ' + responseBody);
8 changes: 8 additions & 0 deletions RESTMessageV2/Jira/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# JIRA Task Creation via ServiceNow Script

This script demonstrates how to create a JIRA task using the JIRA REST API from ServiceNow.

## Requirements

- Valid JIRA instance URL.
- JIRA API token.
Loading