LoginSignup
4
4

More than 5 years have passed since last update.

backlog API を使う③ ~backlogプロジェクトユーザー一覧の取得~

Last updated at Posted at 2017-06-23

1、環境

php4.5
windows7

2、「プロジェクトユーザー一覧の取得」apiを使用する為に必要な情報

公式サイト
https://developer.nulab-inc.com/ja/docs/backlog/api/2/get-project-user-list/

メソッド

GET

URL

/api/v2/projects/:projectIdOrKey/users 

プロジェクトユーザー一覧を取得する為に必要な情報は、以下となります。

パラメーター名 内容
apiKey APIキー(backlog API を使う①参照)
projectIdOrKey プロジェクトのID または プロジェクトキー

4、コード

<?php
/*************************************
* バックログのプロジェクトユーザー一覧を取得する
**************************************/
$backlog_api_key = "作成したAPIキー";
$projectIdOrKey = "プロジェクトid";

$userlist_url = "https://decomarket.backlog.jp/api/v2/projects/".$projectIdOrKey."/users?apiKey=".$backlog_api_key;

$userlist_headers = array('Content-Type: application/x-www-form-urlencoded');
$context = array('http' => array(
  'method' => 'GET',
  'header' => $userlist_headers,
  'ignore_errors' => true
));
$response = file_get_contents($userlist_url, false, stream_context_create($context));
$array = json_decode($response, true);

5、レスポンス例

成功時レスポンス例
[
  {
    "id": 107376xxxx,
    "userId": null,
    "name": "ユーザー名",
    "roleType": 1,
    "lang": null,
    "mailAddress": "xxxxxxxx@xxxxx.co.jp",
    "nulabAccount": null
  },
  {
    "id": 107376xxxx,
    "userId": null,
    "name": "ユーザー名",
    "roleType": 1,
    "lang": null,
    "mailAddress": "xxxxxxxx@xxxxx.co.jp",
    "nulabAccount": null
  },
  {
    "id": 107378xxxx,
    "userId": null,
    "name": "ユーザー名",
    "roleType": 1,
    "lang": null,
    "mailAddress": "xxxxxxxx@xxxxx.co.jp",
    "nulabAccount": {
      "nulabId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "name": "xxxxxxxx",
      "uniqueId": "xxxxxxxx"
    }
  },
  {
  ...
  }
]
失敗時レスポンス例
{
  "errors": [
    {
      "message": "No such project. (key:xxxx)",
      "code": 6,
      "moreInfo": ""
    }
  ]
}

これでユーザーの一覧が取得できました。
次回は指定したユーザにコメントの通知を行ってみたいと思います。

以上です。

4
4
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
4