Create a Jira Issue from Google Sheet

Phil Walburn June 5, 2018

Hi,

Im trying to write a script to create a Jira Issue, when a User fills out a GoogleForm

I keep getting the following error

 

Capture.PNG

 

here is my code

 

Capture.PNG

The fields Project, Summary, Description and Issue Type exist in my Workspace

Can anyone help me ?

thanks

Phil

3 answers

4 votes
ERIK GAUDIN October 1, 2019

Any one know how to use the API method instead ? This one as been anounce as "phase out" starting July 2019... so it won't work very fast.

Franz Gillmeyer November 26, 2021

As far as I know, you can use your e-mail address as user name and generate an API Token on your Jira account that serves as password. Works for me.

1 vote
Tansu Akdeniz
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 5, 2018

Hi @Phil Walburn,

POST URL seems wrong. It should be like "....../rest/api/2/issue".

Here is the link; https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-post

Tansu

Phil Walburn June 5, 2018

Thanks @Tansu Akdeniz

that fixed the problem

Morris Coyle March 1, 2019

Hi @Phil Walburn This is something I have just started looking at however my Apps Script knowledge is somewhat limited at the moment - is there anyway you would be willing to share your code?

Sathish Kannan August 8, 2019

Hi Phil, 

Can you share your brilliance, I'm struggling here because of the 401 error. can you share the code it will be much appreciated.

Thanks,

Kannan

SAP Automation August 8, 2019

Kannan,

try something like this

Phil

 

// Set the Jira Credentials
var username = "YOUR USER NAME"; // <=========================== Set your Username here
var password = "YOUR PASSWORD"; // <=========================== Set your Password here
var UserCredentials = "Basic " + Utilities.base64Encode(username + ":" + password);

var IssueURL = "https://YOUR JIRA URL GOES HERE/rest/api/2/issue"; // <=========================== Set your Jira URL here
var IssueData = {"fields":
{"project": { "key": "ProjectCode" }, // Set the Project
"summary": Summary, // Set the Summary
"description": Description, // Set the Description
"issuetype": {"name": "Enhancement"}, // Set the Enhancement
"priority": {"name": Priority}, // Set the Priority
"customfield_xxxxx" : { "value": "Fieldvaluegoeshere"}

"customfield_xxxxx" : { "value": "Fieldvaluegoeshere"}

}
};

// Call the Jira API
var payload = JSON.stringify(IssueData);

var headers = {"Accept":"application/json",
"Content-Type":"application/json",
"Authorization": UserCredentials,
"muteHttpExceptions": "True"
};

var options = {"method":"POST",
"headers": headers,
"payload" : payload
};

var response = UrlFetchApp.fetch(IssueURL, options);

// Parse the JSON response to use the Issue Key returned by the API in the email
var dataAll = JSON.parse(response.getContentText());
var issueKey = dataAll.key

}

Like # people like this
Sathish Kannan August 8, 2019

Hi Phil, thanks much for the quick help, it works now.

Kannan

Sathish Kannan August 9, 2019

Hi Phil,

Is there a way, such that we can create sub-task for the created Jira ticket. Can you please help on this, I'm new to the scripting.

Kannan.

0 votes
Franz Gillmeyer November 26, 2021

Does anyone know how to use information that you pull from your spreadsheet for your

var data = {"fields": ?

In general the script works. As soon as I add variables that refer to my spreadsheet it doesn't work though. 

My code looks like this

Bildschirmfoto 2021-11-26 um 09.11.00.png

Thanks 

Suggest an answer

Log in or Sign up to answer