REST API

robotsnoindex

Bitbucket Cloud REST API バージョン 1 は削除されました

廃止のご案内を確認するか、バージョン 2.0 の REST API ドキュメントをご参照ください。

限られた 1.0 API リソースの一時的なサポートについて

The 2.0 REST API will rely on the Atlassian Cloud Admin API for user and group management, but those API endpoints are not yet available. Until the Atlassian platform services are fully available in Bitbucket we will continue to support these 1.0 REST endpoints:

Use our REST API, based on open standards, to build third party applications which can use any web development language to access the API. With the API, users can sign in and grant your application the right to make calls on their behalf. Then, through the API, your application can access Bitbucket Cloud resources such as an individual (or team) account, repositories, and aspects of these resources such as changesets or comments.

Atlassian Connect for Bitbucket Cloud

Interested in building integration's with Bitbucket Cloud?

Now you can build right into the Bitbucket Cloud UI with Atlassian Connect for Bitbucket.

連携機能を開発するにあたり、REST アーキテクチャの操作を習得している必要があります。インターネットには、REST に関する多数の優れた資料があります。Bitbucket での REST の実装について理解するには、この概要ページをご参照ください。開始する準備が整ったら、アプリケーションのコンシューマ キーを取得します。

URI 構造とメソッド

All Bitbucket Cloud requests start with the https://api.bitbucket.org/2.0 prefix (for the 2.0 API). The next segment of the URI path depends on the endpoint of the request. For example, using the curl command and the repositories endpoint you can list all the issues on Bitbucket's tutorial repository:

$ curl https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org


特定のエンドポイントを指定して、そのエンドポイントの詳細な情報やリソースを取得することができます。例として、リポジトリの issues リソースがあります。

$ curl https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/issues


エンドポイントやリソースには、一覧のアクション (またはメソッド) が関連付けられています。Bitbucket サービスでは、次の標準 HTTP メソッドがサポートされます。


呼び出し説明
GET情報を取得します。
PUT既存の情報を更新します。
POST新しい情報を作成します。
DELETE既存の情報を削除します。


たとえば、issues リソースで POST アクションを呼び出して、課題トラッカーで課題を作成できます。

コンテンツ長の指定について

411 Length Required r レスポンスが返される場合があります。この場合、API は Content-Length ヘッダーを要求していますが、クライアントがそれを送信していません。したがって、手動でヘッダーを追加する必要があります。たとえば、curl クライアントを使用する場合は次のようになります。

$ curl -r PUT --header "Content-Length: 0" -u user:pass https://api.bitbucket.org/2.0/emails/rap@atlassian.com

Universally Unique Identifier (UUID)

UUID は、ユーザー、チーム、およびリポジトリ向けに単一の識別子を提供します。UUID は、ユーザー名、チーム名、リポジトリ名のフィールドとは独立しており、このようなフィールドが変更されても同じ値が保持されます。たとえば、ユーザーがユーザー名を変更したり、リポジトリを移動した場合、それらへの ID を使用している呼び出しを修正する必要がありますが、UUID を参照している場合は修正は不要になります。

UUID の例と構造

UUID は 2.0 API で、ユーザー、チーム、およびリポジトリに対して使用できます。

以降の例では、次の文字を中括弧の代わりに使用しています。 %7B %7D } の代用です。

ユーザー 

UUID での呼び出し

$ curl https://api.bitbucket.org/2.0/users/%7Bc788b2da-b7a2-404c-9e26-d3f077557007%7D
応答を確認する...
{
   "display_name":"tutorials account",
   "uuid":"{c788b2da-b7a2-404c-9e26-d3f077557007}",
   "links":{
      "hooks":{
         "href":"https://api.bitbucket.org/2.0/users/%7Bc788b2da-b7a2-404c-9e26-d3f077557007%7D/hooks"
      },
      "self":{
         "href":"https://api.bitbucket.org/2.0/users/%7Bc788b2da-b7a2-404c-9e26-d3f077557007%7D"
      },
      "repositories":{
         "href":"https://api.bitbucket.org/2.0/repositories/%7Bc788b2da-b7a2-404c-9e26-d3f077557007%7D"
      },
      "html":{
         "href":"https://bitbucket.org/%7Bc788b2da-b7a2-404c-9e26-d3f077557007%7D/"
      },
      "avatar":{
         "href":"https://bitbucket.org/account/tutorials/avatar/"
      },
      "snippets":{
         "href":"https://api.bitbucket.org/2.0/snippets/%7Bc788b2da-b7a2-404c-9e26-d3f077557007%7D"
      }
   },
   "nickname":"tutorials",
   "created_on":"2011-12-20T16:34:07.132459+00:00",
   "is_staff":false,
   "account_status":"active",
   "type":"user",
   "account_id":null
}


チーム

UUID でのチーム リポジトリの呼び出しは、次のようになります。

$ curl https://api.bitbucket.org/2.0/teams/%7Baa559944-83c9-4963-a9a8-69ac8d9cf5d2%7D


リポジトリ
リポジトリの UUID を取得した場合、API 呼び出しでのユーザー名やチーム名は不要になります。この場合、空白のフィールドを使用できます。これにより、ユーザー名やチーム名に変更があっても対象のリポジトリを解決できます。

チーム名が 1team、リポジトリ名が moxie の場合

$ curl https://api.bitbucket.org/2.0/repositories/1team/moxie


応答は次のようになります。

{
    "updated_on": "2013-11-08T01:11:03.263237+00:00",
    "size": 33348,
    "is_private": false,
    "uuid": "{21fa9bf8-b5b2-4891-97ed-d590bad0f871}"
}


UUID の場合

With empty field:
$ curl https://api.bitbucket.org/2.0/repositories/%7B%7D/%7B21fa9bf8-b5b2-4891-97ed-d590bad0f871%7D

With team name
$ curl https://api.bitbucket.org/2.0/repositories/1team/%7B21fa9bf8-b5b2-4891-97ed-d590bad0f871%7D

サポート対象のエンドポイントおよびそれらのリソース

Bitbucket Cloud supports several endpoints. These endpoints may or may not have additional resources. The table below lists the endpoints and their associated resources.


エンドポイント説明
group-privilegesグループのリポジトリ権限を管理します。
groupsグループとグループのメンバーシップを管理します。
invitationsほかのユーザーをリポジトリに招待します。
users/{accountname}/invitations特定のアカウントの招待の一覧を取得します。

認証

The Bitbucket Cloud API grants access to public data without authentication. Access to private data requires the caller to authenticate under an account with the appropriate access. For example, an account's administrative data, such as the email address, requires the caller to either authenticate as the account owner or, in the case of a team, authenticate as a team member with administrative access to the team. If you are testing an application, you can use a client such as cURL together with basic authentication (username/password, or if you have two-step verification enabled, username/app password).


たとえば次の curl 呼び出しは、bbdocs ユーザーの非公開および公開リポジトリの一覧を取得します。

$ curl --user bbdocs:bbpassword https://api.bitbucket.org/2.0/repositories/bbdocs

Bitbucket と連携するアプリケーションを構築している場合、コンシューマ キーを取得し、OAuth 2.0 フレームワークを使用して認証します。OAuth と Bitbucket の詳細については、このドキュメントの「Bitbucket Cloud での OAuth」をご参照ください。

最終更新日 2020 年 6 月 24 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.