I am trying to send an authentication token in a request to Jira from Google Apps Scripts. I haven't been able to make it work. I've tried using tokens by base64 encoding my email and password as well as ones from the API token section of my profile. Neither works. I have success using a colleague's token, but he doesn't know how he got it. Any help would be appreciated!
function testEdit(){
let headers = {
"content-type": "application/json",
"Accept": "application/json",
"Authorization": "Basic Y2hhc2XXXXX” //Chase
};
// A final few options to complete the JSON string
let data =
{
"fields" : {
//"customfield_10110" :
"summary":
{"value" : "foo"}
}
};
var payload = JSON.stringify(data);
var options = {
"content-type": "application/json",
"method": “PUT”,
"headers": headers,
"payload": payload,
"muteHttpExceptions":false
};
var response = UrlFetchApp.fetch("http://whisper.atlassian.net/rest/api/2/issue/IMG-1625", options);
let responseContent = response.getContentText();
let jsonContent = JSON.parse(responseContent);
Logger.log(jsonContent.key);
}
Using email and password for authentication won't work. You must use email and a token, Base64 encoded.
If your token does not work, I would recommend the following:
Thanks, Marc. When you say "generate a token", do you mean from the "Generate API token" of my Jira account, or from Base64 encoding my username and password, or from something else?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should generate a token from the "Generate API token" account page. Then take this token like `Password:Token`, and base64 encode the result. This base64 encoded string is what you use when accessing Jira.
However, make sure you understand how AppsScript is calling the API. Maybe AppsScript already does the base64 encoding for you.
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.