0
0

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 1 year has passed since last update.

trello の rest api をたたいてカード作ったり動かしたりする。

Last updated at Posted at 2023-04-13

API KEYとAPI TOKENの取得

https://trello.com/app-key にアクセスして、 Power-Up管理者ポータルへ移動し、作成のリンクに移動し、必要なことを入力する。Power-UpとかREST API使うのにキーが欲しいのに何これ?と思っても進むとキーとトークンが得られる。
なんかこんなの使わないよcurlでAPIたたくだけしかしないよと思ってもそれっぽい値を入力して進む。
そうすると、APIキーが生成されて表示される。秘密(多分secret)は無視する。そこの手動でトークンを生成できますのリンクを辿り、
以下のアプリケーションへアウントへのアクセスをを許可しますかで許可をする。とトークンが表示されるので、コピーしてメモっておく。

trelloの操作

メンバー取得

これでメンバーのidを取得する。

curl -s "https://api.trello.com/1/members/$username?key=$apikey&token=$token"

ボードID取得

curl "https://trello.com/1/members/$username/boards?key=$apikey&token=$token"

list ID一覧

curl "https://trello.com/1/boards/$boardid/lists?key=$apikey&token=$token&fields=name"

カード移動

curl --request PUT \
     --url "https://api.trello.com/1/cards/$cardid" \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --data "{
       \"idList\": \"${listid_working}\",
       \"key\": \"${apikey}\",
       \"token\": \"${token}\"
     }"

カード作成

curl -X POST "https://trello.com/1/cards?key=$apikey&token=$token&idList=$listid&name=i_create_a_new_card"

もしくは

curl -X POST "https://trello.com/1/cards?key=$apikey&token=$token&idList=$listid" \
  --data-urlencode "name=I create a new card."

カード作成

curl --request POST \
     --url 'https://api.trello.com/1/cards' \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --data "{
       \"name\": \"a new card name\",
       \"idList\": \"$listid\",
       \"idMembers\": \"$userid\",
       \"idLabels\": \"$labelid\",
       \"due\": \"2023-04-28T12:00:00.000Z\",
       \"desc\": \"description is here.\",
       \"comments\": \"hello, world!\",
       \"key\": \"${apikey}\",
       \"token\": \"${token}\"
     }"

アクティビティログにコメントを追加する

curl -X POST -H "Content-Type: application/json" \
    -d '{"text": "アクティビティログに追加するコメント"}' \
    "https://api.trello.com/1/cards/${cardid}/actions/comments?key=${apikey}&token=${token}"

カードをアーカイブする

curl -X PUT -H "Content-Type: application/json" \
   -d '{"closed": true}' \
   "https://api.trello.com/1/cards/${cardid}?key=${apikey}&token=${token}"

カード取得

curl -s "https://api.trello.com/1/search?query=$userid&modelTypes=cards&key=$apikey&token=$token" 

jq 使ってフィルタ

cat foo.json | jq '.cards[] | select(.closed == false and .idList != "1234567890" )  | {name, id, desc, idList, labels: [.labels[] | {id: .id, name: .name}], comment: .badges.comments, closed }'
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?