LoginSignup
4

More than 5 years have passed since last update.

bitbucketのAPIを使って、ダウンロードファイルの作成/取得を行う

Posted at

bitbucketのAPIを使って、ダウンロードファイルの作成と取得を行うことができます。
これを利用すれば、例えばバイナリファイルのデプロイを行うことができます。

アプリパスワードの作成

APIの認証にはBasic認証を使うことも出来ますが、パスワードを晒したくない場合はアプリパスワードで認証することをお勧めします。
以下のリンクを参考に、アプリパスワードを作成してください。
また、ダウンロードファイルのAPIを利用するため、リポジトリの書き込み権限を付与してください。

ダウンロードファイル作成

POST /2.0/repositories/{username}/{repo_slug}/downloads

$ echo Hello World > hello.txt
$ curl --user $USER_ID:$APP_PASSWORD -X POST https://api.bitbucket.org/2.0/repositories/evzijst/git-tests/downloads -F files=@hello.txt

ダウンロードファイル取得

GET /2.0/repositories/{username}/{repo_slug}/downloads/{filename}

$ curl --user $USER_ID:$APP_PASSWORD -L https://api.bitbucket.org/2.0/repositories/evzijst/git-tests/downloads/hello.txt
Hello World

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