You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I wanted to automate a Google Sheet that I have been creating manually for a weekly meeting which shows the issues in a project that have not been updated in the last 15 days. When running the script, but nothing writes to the Google Sheet despite no error showing up. What I did note was that after running a "console.log(response.getContentText())" before the IF, I see that my query is returning a Cloudflare error
Is there something improper in my construction and/or use of the JIRA API to cause this?
function getJiraIssues() {
var username = "<my_jira_username>";
var apiToken = "<my_jira_password>";
var jqlQuery = "project=xyz AND issuetype = Bug)";
var sheet = SpreadsheetApp.getActiveSheet();
var headers = sheet.getRange(1, 1, 1, 8).getValues()[0];
var options = {
'method': 'get',
'contentType': 'application/json',
'headers': {
'Authorization': 'Basic ' + Utilities.base64Encode(username + ':' + apiToken)
},
'muteHttpExceptions': true
};
var url = 'https://<my_jira_instance>.jira.com/rest/api/2/search?jql=' + encodeURIComponent(jqlQuery);
var response = UrlFetchApp.fetch(url, options);
if (response.getResponseCode() === 200) {
var data = JSON.parse(response.getContentText());
var issues = data.issues.map(function(issue) {
var issueData = {};
issueData['Issue Summary'] = issue.fields.summary;
issueData['Assignee'] = issue.fields.assignee ? issue.fields.assignee.displayName : '';
issueData['Issue Key'] = issue.key;
issueData['Issue Type'] = issue.fields.issuetype.name;
issueData['Component/s'] = issue.fields.components.map(function(component) {
return component.name;
}).join(', ');
issueData['Status'] = issue.fields.status.name;
issueData['Created'] = issue.fields.created;
issueData['Updated'] = issue.fields.updated;
return issueData;
});
var row = sheet.getLastRow() + 1;
var numRows = issues.length;
var numCols = headers.length;
sheet.getRange(row, 1, numRows, numCols).setValues(issues.map(function(issue) {
return headers.map(function(header) {
return issue[header];
});
}));
}
}
Hi @Jeff A
It seems that the JQL query string you're using has an extra closing parenthesis at the end, which is causing the Cloudflare error.
Please try to use this :
function getJiraIssues() {
var username = "<my_jira_username>";
var apiToken = "<my_jira_password>";
var jqlQuery = "project=xyz AND issuetype=Bug";
var sheet = SpreadsheetApp.getActiveSheet();
var headers = sheet.getRange(1, 1, 1, 8).getValues()[0];
var options = {
'method': 'get',
'contentType': 'application/json',
'headers': {
'Authorization': 'Basic ' + Utilities.base64Encode(username + ':' + apiToken)
},
'muteHttpExceptions': true
};
var url = 'https://<my_jira_instance>.jira.com/rest/api/2/search?jql=' + encodeURIComponent(jqlQuery);
var response = UrlFetchApp.fetch(url, options);
if (response.getResponseCode() === 200) {
var data = JSON.parse(response.getContentText());
var issues = data.issues.map(function(issue) {
var issueData = {};
issueData['Issue Summary'] = issue.fields.summary;
issueData['Assignee'] = issue.fields.assignee ? issue.fields.assignee.displayName : '';
issueData['Issue Key'] = issue.key;
issueData['Issue Type'] = issue.fields.issuetype.name;
issueData['Component/s'] = issue.fields.components.map(function(component) {
return component.name;
}).join(', ');
issueData['Status'] = issue.fields.status.name;
issueData['Created'] = issue.fields.created;
issueData['Updated'] = issue.fields.updated;
return issueData;
});
var row = sheet.getLastRow() + 1;
var numRows = issues.length;
var numCols = headers.length;
sheet.getRange(row, 1, numRows, numCols).setValues(issues.map(function(issue) {
return headers.map(function(header) {
return issue[header];
});
}));
}
}
the corrected query string is
var jqlQuery = "project=xyz AND issuetype=Bug";
That's a good catch, thank you very much. Unfortunately, I am still getting the same Cloudflare Error even after correcting it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.