Bitbucket is getting a new navigation

We’re rolling out these changes, so the documentation may not match your experience in the Bitbucket Cloud app. Read about the new Bitbucket navigation

API トークンの使用

API トークンは、ユーザー アクセスのスコープが定義された単一目的のアクセス トークンです (作成時に指定)。これらのトークンは、スクリプト作成、CI/CD ツール、 Bitbucket に接続される開発中のアプリのテストに役立ちます。

Bitbucket API へのアクセスや Git コマンドの実行に使用される API トークンにはスコープが必要です

Git コマンドで API トークンを使用する

To authenticate with Bitbucket Cloud using an API token, you will need the API token and your Bitbucket username. Your Bitbucket username is listed under Bitbucket profile settings on your Bitbucket Account settings page.

インタラクティブ パスワード プロンプトによる API トークン

この方法では、API トークンが保護されずに URL に保存されるのを防ぎ、Git が Bitbucket Cloud を操作 (git pullgit pushgit fetch などのコマンドを実行) するたびにトークンの入力を要求します。

パスワードを求められた場合は、必ず API トークンを入力してください。

インタラクティブ プロンプトを介して API トークンを指定するには、次のコマンドでリポジトリを複製します。

git clone https://{bitbucket_username}@bitbucket.org/{workspace}/{repository}.git

または、以下の例のように、静的ユーザー名「x-bitbucket-api-token-auth」を使用することもできます。静的ユーザー名は、Git とのやり取りにさらに多くのオプションを提供し、特にアプリや統合での Git とのやり取りを簡素化します。

git clone https://x-bitbucket-api-token-auth@bitbucket.org/{workspace}/{repository}.git

ローカルデバイスにすでに複製されているリポジトリの場合は、次のコマンドでリモート URL をアップデートします。

git remote set-url origin https://{bitbucket_username}@bitbucket.org/{workspace}/{repository}.git

API トークンを URL に含める

API トークンをプレーンテキストとして保護しないで保存したり、Git リモート URL の一部として永続的に保存したりしないことをお勧めします。この方法は、API トークンがビルド ツールの「秘密」変数として安全に保存されている場合に役立ちます。

インタラクティブ パスワード プロンプトなしで API トークンを使用するために、API トークンを URL に含めることができます。例: リポジトリを複製する場合は、次のコマンドを実行します。

git clone https://{bitbucket_username}:{api_token}@bitbucket.org/{workspace}/{repository}.git

代わりに、静的なユーザー名を使用することもできます。

git clone https://x-bitbucket-api-token-auth:{api_token}@bitbucket.org/{workspace}/{repository}.git

ローカルデバイスにすでに複製されているリポジトリの場合は、次のコマンドでリモート URL をアップデートします。

git remote set-url origin https://{bitbucket_username}:{api_token}@bitbucket.org/{workspace}/{repository}.git

Bitbucket API で API トークンを使用する

If you are building an integration or app for Bitbucket Cloud, we recommend using OAuth where possible. For information on building a Bitbucket Cloud integration or app, visit Atlassian Developer - Bitbucket Cloud.

The following examples show how to use an API token with the curl command as a guide for how to authenticate with Bitbucket Cloud APIs. Both examples are querying the commits on a Bitbucket repository using the List commits API. You will need both your Atlassian account email and an API token. Your Atlassian account email is listed under Email Aliases on your Bitbucket Personal settings page.

API トークンは、ユーザーの Atlassian アカウント メールとともに、ログイン認証情報として送信できます。次に例を示します。

curl --request POST \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/commits' \ --user '{atlassian_account_email}:{api_token}' \ --header 'Accept: application/json'

Alternatively, they can be sent in a HTTP Authorization header after the Bitbucket email and API token have been base64 encoded. For example:

my_credentials_after_base64_encoding=`echo -n '{atlassian_account_email}:{api_token}' | base64` curl --request POST \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/commits' \ --header "Authorization: Basic $my_credentials_after_base64_encoding" \ --header 'Accept: application/json'

 

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。