公式リファレンスを参考に、以下のコード.gsでいけました。
事前準備
- 「BASE_URL」と「issueKey」は各自の値を設定します
- スクリプトのプロパティに「token」という名でbase64Encodeしたトークンを入れておきます
tokenについては別途こちらにも書きました
コード.gs
var BASE_URL = "https://SITENAME.atlassian.net";
var issueKey = "KT-8";
function addComment() {
var data = {
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "added comment",
"type": "text"
}
]
}
]
}
}
var options = {
method: 'post',
contentType: 'application/json',
headers: {'Authorization': ' Basic ' + getToken()},
payload: JSON.stringify(data)
}
var url = BASE_URL + '/rest/api/3/issue/' + issueKey + "/comment";
UrlFetchApp.fetch(url, options);
}
function getToken() {
return PropertiesService.getScriptProperties().getProperty('token');
}
|
補足
上記は REST API v3 の場合で
v2 の場合は以下のコード2.gsでいけました。
コード2.gsvar BASE_URL = "https://SITENAME.atlassian.net";
var issueKey = "KT-8";
function addComment() {
var data = {
"body": "added comment v2"
}
var options = {
method: 'post',
contentType: 'application/json',
headers: {'Authorization': ' Basic ' + getToken()},
payload: JSON.stringify(data)
}
var url = BASE_URL + '/rest/api/2/issue/' + issueKey + "/comment";
UrlFetchApp.fetch(url, options);
}
function getToken() {
return PropertiesService.getScriptProperties().getProperty('token');
}
|
参考
Add comment v3
https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-issue-issueIdOrKey-comment-post
Add comment v2
https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-comment-post