LoginSignup
4
5

More than 5 years have passed since last update.

backlog API を使う② ~backlogの課題にコメントをする~

Last updated at Posted at 2017-06-22

1、環境

php4.5
windows7

2、「課題コメントの追加」apiを使用する為に必要な情報

公式サイト
https://developer.nulab-inc.com/ja/docs/backlog/api/2/add-comment/

メソッド

POST

URL

/api/v2/issues/:issueIdOrKey/comments 

backlogの課題にコメントをする為に最低限必要な情報は、以下となります。

パラメーター名 内容
apiKey APIキー(backlog API を使う①参照)
issueIdOrKey コメントしたい課題番号
content コメント内容

追加で以下も設定可能です。
次回以降使い方を書こうと思います。

パラメーター名 内容
notifiedUserId[] コメント登録の通知を受け取るユーザーID(backlog API を使う③参照)
attachmentId[] 添付ファイルの送信APIが返すID(backlog API を使う⑤参照)

3、issueIdOrKeyとは何にあたるのか

課題番号のことです。

HOGE-12

ブラウザのurl上では、以下のように見えている部分となります。

https://xxx.backlog.jp/view/HOGE-12

4、コード

<?php
/**************************
* backlogの課題にコメントを送信する
***************************/
$issueIdOrKey = "HOGE-12"; // コメントしたい課題番号
$backlog_api_key = "作成したAPIキー";
$comment = "コメント";

$comment_url = "https://xxx.backlog.jp/api/v2/issues/".$issueIdOrKey."/comments?apiKey=".$backlog_api_key;
$params = array(
  'content' => $comment
);
$comment_url = $comment_url . "&".http_build_query($params, "", "&");
$comment_headers = array('Content-Type: application/x-www-form-urlencoded');
$context = array('http' => array(
  'method' => 'POST',
  'header' => $comment_headers,
  'ignore_errors' => true
));
$response = file_get_contents($comment_url, false, stream_context_create($context));

5、レスポンス例

成功時レスポンス例
{
  "id":1169932xxx,
  "content":"コメント",
  "changeLog":[],
  "createdUser":
    {
      "id":1073766xxx,
      "userId":"mori",
      "name":"バックログのユーザー名",
      "roleType":2,
      "lang":null,
      "mailAddress":"xxxx@xxxx.co.jp",
      "nulabAccount":null
    },
  "created":"2017-06-22T06:15:40Z",
  "updated":"2017-06-22T06:15:40Z",
  "stars":[],
  "notifications":[]
}
失敗時レスポンス例
{
  "errors": [
    {
      "message": "Undefined resource. /api/v2/HOGE-12/comments",
      "code": 6,
      "moreInfo": ""
    }
  ]
}

成功すれば、バックログの課題にコメントが確認できると思います!

以上です。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5