LoginSignup
3
3

More than 5 years have passed since last update.

CircleCIで提供しているAPIのTIPS

Posted at

APIの使い方

GET: /me」の例

例)
TOKEN="12345abcd・・・・"
curl -s -u ${TOKEN}: https://circleci.com/api/v1.1/me
# もしくは
curl https://circleci.com/api/v1.1/me?circle-token=${TOKEN}

参考URL

説明

  • トークン(TOKEN)の作成方法
    • https://circleci.com/account/apiで作成
  • プロジェクト(ブランチ)別にトークンを分ける方法
    • https://circleci.com/gh/<CircleCIのユーザ名もしくは組織名>/<ブランチ名>/edit#apiで作成
  • CircleCIのAPIのendpointsは、全てhttps://circleci.com/api/v1.1/で始まる
  • curlのオプション
    • -s, --silent
      • サイレントモード、エラーメッセージなどが出ない
    • -u, --user <user:password>
      • 認証のためのユーザ名とパスワード用のオプション、今回はトークンのみ指定
  • /meのURIを叩くと{ "message" : "You must log in first." }のエラーが出る場合は、ブラウザで確認してみる
    • ブラウザでの確認方法:ブラウザでCircleCIにログインした状態で、別タブにhttps://circleci.com/api/v1.1/meを入力
    • なぜAPIが叩けないのかを調査する場合はcurl -vのオプションを付ける
      • 認証が通っていないときは401 Unauthorizedが出る、その場合はトークンがうまく作れていない場合が多い

GET: /project/:vcs-type/:username/:project」の例

例)
TOKEN="12345abcd・・・・"
# guthubと連携している場合
curl -s -u ${TOKEN}: https://circleci.com/api/v1.1/project/github/<CircleCIのユーザ名もしくは組織名>/<ブランチ名>
# もしくは
curl https://circleci.com/api/v1.1/project/github/<CircleCIのユーザ名もしくは組織名>/<ブランチ名>?circle-token=${TOKEN}

2018-09-05

APIの一覧 (2018-09-05現在)

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