LoginSignup
6
3

More than 3 years have passed since last update.

Backlog API と curlコマンド対応メモ

Last updated at Posted at 2020-05-03

Backlog APIをcurlコマンドで叩いてみたメモです。
Backlog APIごとのパラメーターの渡し方に悩むので、備忘録として書いておきます。
自分が必要な都度追記していきます。

共通設定

以下で試すcurlコマンドの共通設定です。

APIKEY="<API Key>"
BACKLOG_URL="https://<Backlogアカウント>.backlog.com"

環境

  • mac OS10.14.6
  • jq
  • bash

プロジェクト関連

プロジェクト一覧の取得

プロジェクト一覧の取得

コマンド
curl -s $BACKLOG_URL/api/v2/projects\?apiKey=$APIKEY\&archived=false | jq -r '.[]'
実行結果
$ bash project.bash 
{
  "id": <プロジェクトid>,
  "projectKey": <"プロジェクトKey">,
  "name": "プログラミング開発",
  "chartEnabled": false,
  "subtaskingEnabled": false,
  "projectLeaderCanEditProjectLeader": false,
  "useWikiTreeView": true,
  "textFormattingRule": "markdown",
  "archived": false,
  "displayOrder": 2147483646
}

プロジェクトの状態一覧の取得

プロジェクトの状態一覧の取得

コマンド
APIKEY="<API Key>"
BACKLOG_URL="https://<Backlogアカウント>.backlog.com"
curl -s $BACKLOG_URL/api/v2/projects/<プロジェクトKey又はプロジェクトId>/statuses\?apiKey=$APIKEY | jq -r '.[]'
実行結果
$ bash project.bash 
{
  "id": 1,
  "projectId": 19547,
  "name": "未対応",
  "color": "#ed8077",
  "displayOrder": 1000
}
{
  "id": 2,
  "projectId": 19547,
  "name": "処理中",
  "color": "#4488c5",
  "displayOrder": 2000
}
{
  "id": 3,
  "projectId": 19547,
  "name": "処理済み",
  "color": "#5eb5a6",
  "displayOrder": 3000
}
{
  "id": 4,
  "projectId": 19547,
  "name": "完了",
  "color": "#b0be3c",
  "displayOrder": 4000
}

課題関連

課題一覧の取得

課題一覧の取得

# プロジェクトIDごとの課題一覧を取得
# Backlog APIのクエリパラメータ内の[]を無効にする為に、crulに -g オプションを付けています
curl -g -s $BACKLOG_URL/api/v2/issues\?apiKey=$APIKEY\&parentChild=0\&projectId[]=19547\&count=100 | jq -r '.[]'
# プロジェクトの状態(ステータス)をクエリパラメータに設定
# statusシェル変数にステータスの配列から0番目のステータスIDを取得
status=`curl -s $BACKLOG_URL/api/v2/projects/19547/statuses\?apiKey=$APIKEY | jq -r '.[0] | .id'`
curl -g -s $BACKLOG_URL/api/v2/issues\?apiKey=$APIKEY\&parentChild=0\&projectId[]=19547\&statusId[]=$status\&count=100 | jq -r '.[]'

# ステータス名"完了"から、ステータスIDを取得してもOK
status=`curl -s $BACKLOG_URL/api/v2/projects/19547/statuses\?apiKey=$APIKEY | jq -r '.[] | select(.name == "完了") | .id'`

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