Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Google Script issue - Not working since last JIRA update

ERIK GAUDIN
Contributor
March 3, 2020

Here how i use the GScript :
Gform ---> GSheet --- > GScript ---> JIRA
In GForm, i took the user e-mail direct from there. And ask for some usual variable (using dropdown menu)


The variable "AssignedSupervisor" was something set in the GForm. So i use the user ID found in JIRA, and
simply re-use that.. exemple, if the user named "Robert Aly" and his Jira User Key is "robert.aly", i simply use
a dropdown field with that value. Once the user finish the form, the script is trigger by the GForm and create the ticket, and send him e-mail contain the JIRA URL to this ticket.


1 or 2 weeks ago... all seem not working. Something seem to have happen, preventing the Script to filled "assignee" and "reporter"


var token64 = Utilities.base64Encode(USER_AUTH + ":" + API_TOKEN);

var headers = {
"content-type": "application/json",
"Accept": "application/json",
"Authorization": "Basic " + token64
};

var searchUsersOptions = {
"content-type": "application/json",
"method": "GET",
"headers": headers,
"muteHttpExceptions": false
};

var searchUsersResponse = UrlFetchApp.fetch(searchUserUrl, searchUsersOptions);

var searchUserResults = JSON.parse(searchUsersResponse.getContentText());

if (searchUserResults.length != 1) {
Logger.log(searchUsersResponse);
throw Error(requesterEmail + " cant find email or more than one find with that email.");
}


var data = {
"fields": {
"project": {
"key": projetkey
},
"priority": {
"name": UrgencePrio
},
"duedate": formattedDate,
"assignee" : {"name" : AssignedSupervisor},
"summary": ProjectNameWithAssignee,
"customfield_12178" : WBSNumberBudgetEst,
"description": Descriptionetdoclink,
"labels" : etiquettesautiliser,
"reporter": {
"emailAdress": requesterEmail
},
"issuetype": {
"name": TaskType


I got those error now
{ [Exception: Request failed for https://mydomainname.atlassian.net returned code 400. Truncated server response: {"errorMessages":[],"errors":{"reporter":"Reporter is required."}} (use muteHttpExceptions option to examine full response)] name: 'Exception' }

 

Anyone know how to adress those issue ? I give full Admin right to the user attached to the Script, without better result (so it's not a right issue)

1 answer

1 accepted

0 votes
Answer accepted
Ben Kelley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 3, 2020

I suspect the problem is that user names are no longer supported. See https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/

There wasn an announcement in October 2018 that user names were being deprecated. You need to specify users using their account ID. You can no longer use "name" for user name.

Note that the error you are seeing is about reporter. You specified the reporter using "emailAddress" which is not valid.

You want something like:

"reporter": {"accountId": "abc-1234-def"}
ERIK GAUDIN
Contributor
March 4, 2020

How do i querry the Account ID from e-mail ?

 

I'm using this que Querry the API with e-mail  :

var searchUserUrl = "https://mydomain.atlassian.net/rest/api/2/user/search?username=" + requesterEmail + "&startAt&maxResults&includeActive&includeInactive";

Then search inside (to get the full response)


var searchUsersResponse = UrlFetchApp.fetch(searchUserUrl, searchUsersOptions);

var searchUserResults = JSON.parse(searchUsersResponse.getContentText());

"assignee" : {"accountId" : searchUserResults[0].accountId},

"reporter": {"accountId": ???},

I got no error... but "assignee" not working.

 

Any idea ?

If i try the API command on the browser, i got some result : https://ourdomain.atlassian.net/rest/api/3/user/search?username=useremail@mydomain.ca&startAt&maxResults&includeActive&includeInactive

 

 

If i input manually the AccountID .. it work

ERIK GAUDIN
Contributor
March 5, 2020

Found my error...

AccountId   instead of AccountI

 

 

Everything works fine by using the AccountId instead of the Jira KEY.

 

Thanks to point me out to that change !

Pooja Varde
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 20, 2022

Hi , I am still not able to update reporter in jira issue. Here is my code : 

var requesterEmail = e.values[9];
var encCred = "xyz"; //https://www.base64encode.org/ username:password

var headers = { "Accept":"application/json",
"Content-Type":"application/json",
"Authorization":"Basic " + encCred,
};

//
//get user account as reporter
var searchUsersOptions = {
"content-type": "application/json",
"method": "GET",
"headers": headers,
"muteHttpExceptions": false
};
var searchUserUrl = "xyz/rest/api/2/user/search?username=" + requesterEmail;

//Then search inside (to get the full response)


var searchUsersResponse = UrlFetchApp.fetch(searchUserUrl, searchUsersOptions);

var searchUserResults = JSON.parse(searchUsersResponse.getContentText());


//
//
var data = {
"fields": {
"project": {
"key": "xyz"
},
"summary": summary,
"description": description,
"issuetype": {
"name": "Demo - Scrum (Agile)"
},
"reporter" : {"accountId" : searchUserResults[0]}
}
};
//
// Turn all the post data into a JSON string to be send to the API
//
var payload = JSON.stringify(data);

var options = { "method":"POST",
"contentType" : "application/json",
"headers": headers,
"payload" : payload
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
//
// 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
Logger.log(dataAll)

//
Ben Kelley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 20, 2022

@Pooja Varde are you working with Jira Cloud? I wouldn't expect this to work with cloud. "/rest/api/2/user/search?username="

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events