2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

backlog API を使う④ ~backlogプロジェクトユーザにコメントを通知する~

Last updated at Posted at 2017-06-28

#1、環境
php4.5
windows7

#2、必要な情報
公式サイト
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 を使う③参照)

#3、コード

<?php
/**************************
* backlogの課題にコメントを送信しユーザーに通知する
***************************/
$issueIdOrKey = "HOGE-12"; // コメントしたい課題番号
$backlog_api_key = "作成したAPIキー";
$comment = "コメント";
$notifiedUserId_001 = "コメントの通知を受け取るユーザーID(1人目)";
$notifiedUserId_002 = "コメントの通知を受け取るユーザーID(2人目)";

$comment_url = "https://xxx.backlog.jp/api/v2/issues/".$issueIdOrKey."/comments?apiKey=".$backlog_api_key;
$params = array(
  'content' => $comment,
  'notifiedUserId[0]' => $notifiedUserId_001,
  'notifiedUserId[1]' => $notifiedUserId_002
);
$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));

#4、レスポンス例

成功時レスポンス例
{
  "id": 117039xxxx,
  "content": "コメントテストです。",
  "changeLog": [],
  "createdUser": {
    "id": 107376xxxx,
    "userId": "mori",
    "name": "バックログのユーザー名",
    "roleType": 2,
    "lang": null,
    "mailAddress": "xxxx@xxxxxx.co.jp",
    "nulabAccount": null
  },
  "created": "2017-06-28T03:00:56Z",
  "updated": "2017-06-28T03:00:56Z",
  "stars": [],
  "notifications": [
    {
      "id": 8057xxxx,
      "alreadyRead": false,
      "reason": 2,
      "user": {
        "id": 10738xxxx,
        "userId": null,
        "name": "通知先のバックログのユーザー名",
        "roleType": 1,
        "lang": null,
        "mailAddress": "xxxxxxxxxx@xxxx.co.jp",
        "nulabAccount": null
      },
      "resourceAlreadyRead": false
    }
  ]
}
失敗時レスポンス例
{
  "errors": [
    {
      "message": "Undefined resource. /api/v2/HOGE-12/comments",
      "code": 6,
      "moreInfo": ""
    }
  ]
}

成功すれば、バックログの課題にコメントと特定ユーザーへの通知が確認できると思います!

以上です。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?