課題作成時にラベルを追加する場合はこう書くらしい
{
fields:
{
labels: ["ラベル1", "ラベル2"]
}
};
コード.gs
var BASE_URL = 'https://SITENAME.atlassian.net/rest/api/2/';
function doPost() {
var payload = get_payload();
var options = get_options(payload);
var response = UrlFetchApp.fetch(BASE_URL + "issue/", options);
var key = get_key(response);
Logger.log(key);
}
function get_payload(values) {
var email = Session.getActiveUser().getEmail();
var data = {
project: {key: "KT"},
issuetype: {name: "Task"},
priority: {name: 'Medium'},
summary: "たいとる",
description: "タスクの説明です\n説明の2行め",
//customfield_10026: "対象のカスタムフィールドに入れる値",
reporter: {id: getAccountId()},
labels: ["ラベル1", "ラベル2"]
};
var fields = {fields: data};
var payload = JSON.stringify(fields);
return payload;
}
function get_options(payload) {
var options = {
method: "post",
payload: payload,
contentType: "application/json",
headers: {"Authorization": " Basic " + getToken()}
}
return options;
}
function get_key(response){
var jobj = JSON.parse(response);
var key = jobj["key"];
return key;
}
function getAccountId() {
var project = 'KT';//プロジェクトを指定する
var email = Session.getActiveUser().getEmail();
var url = BASE_URL + 'user/search?query=' + email;
var options = {
method: "get",
contentType: "application/json",
headers: {"Authorization": " Basic " + getToken()}
}
var response = UrlFetchApp.fetch(url, options);
var jobj = JSON.parse(response);
var accountInfo = getAccountInfo(jobj, email);
var accountId = accountInfo['accountId'];
return accountId;
}
function getAccountInfo(jobj, email) {
var accountInfo;
for(var i = 0; i < jobj.length; i++) {
var emailAddress = jobj[i]['emailAddress'];
if(emailAddress === email) {
accountInfo = jobj[i];
}
}
return accountInfo;
}
|
関連記事
JIRA APIでissueを作成する
JIRAのAPIでemailからaccountIdを取得したい
