Repositories 1 endpoints

GET /user/permissions/repositories

Returns an object for each repository the caller has explicit access
to and their effective permission — the highest level of permission the
caller has. This does not return public repositories that the user was
not granted any specific permission in, and does not distinguish between
explicit and implicit privileges.

Permissions can be:

  • admin
  • write
  • read

Results may be further filtered or sorted by
repository or permission by adding the following query string
parameters:

  • q=repository.name="geordi" or q=permission>"read"
  • sort=repository.name

Note that the query parameter values need to be URL escaped so that =
would become %3D.

operationId: Repositories_listUserPermissions

Parameters

Name In Required Type Description
q query optional string

Query string to narrow down the response as per
filtering and sorting.

sort query optional string

Name of a response property sort the result by as per
filtering and sorting.

Responses

200

Repository permissions for the repositories a caller has explicit access to.

GET /user/permissions/repositories

Snippets 24 endpoints

GET /snippets

Returns all snippets. Like pull requests, repositories and workspaces, the
full set of snippets is defined by what the current user has access to.

This includes all snippets owned by any of the workspaces the user is a member of,
or snippets by other users that the current user is either watching or has collaborated
on (for instance by commenting on it).

To limit the set of returned snippets, apply the
?role=[owner|contributor|member] query parameter where the roles are
defined as follows:

  • owner: all snippets owned by the current user
  • contributor: all snippets owned by, or watched by the current user
  • member: created in a workspaces or watched by the current user

When no role is specified, all public snippets are returned, as well as all
privately owned snippets watched or commented on.

The returned response is a normal paginated JSON list. This endpoint
only supports application/json responses and no
multipart/form-data or multipart/related. As a result, it is not
possible to include the file contents.

operationId: Snippets_list

Parameters

Name In Required Type Description
role query optional string

Filter down the result based on the authenticated user’s role (owner, contributor, or member).

Responses

200

A paginated list of snippets.

404

If the snippet does not exist.

GET /snippets
POST /snippets

Creates a new snippet under the authenticated user’s account.

Snippets can contain multiple files. Both text and binary files are
supported.

The simplest way to create a new snippet from a local file:

$ curl -u username:password -X POST https://api.bitbucket.org/2.0/snippets               -F file=@image.png

Creating snippets through curl has a few limitations and so let’s look
at a more complicated scenario.

Snippets are created with a multipart POST. Both multipart/form-data
and multipart/related are supported. Both allow the creation of
snippets with both meta data (title, etc), as well as multiple text
and binary files.

The main difference is that multipart/related can use rich encoding
for the meta data (currently JSON).

multipart/related (RFC-2387)

This is the most advanced and efficient way to create a paste.

POST /2.0/snippets/evzijst HTTP/1.1
Content-Length: 1188
Content-Type: multipart/related; start="snippet"; boundary="===============1438169132528273974=="
MIME-Version: 1.0

--===============1438169132528273974==
Content-Type: application/json; charset="utf-8"
MIME-Version: 1.0
Content-ID: snippet

{
  "title": "My snippet",
  "is_private": true,
  "scm": "git",
  "files": {
      "foo.txt": {},
      "image.png": {}
    }
}

--===============1438169132528273974==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-ID: "foo.txt"
Content-Disposition: attachment; filename="foo.txt"

foo

--===============1438169132528273974==
Content-Type: image/png
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID: "image.png"
Content-Disposition: attachment; filename="image.png"

iVBORw0KGgoAAAANSUhEUgAAABQAAAAoCAYAAAD+MdrbAAABD0lEQVR4Ae3VMUoDQRTG8ccUaW2m
TKONFxArJYJamCvkCnZTaa+VnQdJSBFl2SMsLFrEWNjZBZs0JgiL/+KrhhVmJRbCLPx4O+/DT2TB
cbblJxf+UWFVVRNsEGAtgvJxnLm2H+A5RQ93uIl+3632PZyl/skjfOn9Gvdwmlcw5aPUwimG+NT5
EnNN036IaZePUuIcK533NVfal7/5yjWeot2z9ta1cAczHEf7I+3J0ws9Cgx0fsOFpmlfwKcWPuBQ
73Oc4FHzBaZ8llq4q1mr5B2mOUCt815qYR8eB1hG2VJ7j35q4RofaH7IG+Xrf/PfJhfmwtfFYoIN
AqxFUD6OMxcvkO+UfKfkOyXfKdsv/AYCHMLVkHAFWgAAAABJRU5ErkJggg==
--===============1438169132528273974==--

The request contains multiple parts and is structured as follows.

The first part is the JSON document that describes the snippet’s
properties or meta data. It either has to be the first part, or the
request’s Content-Type header must contain the start parameter to
point to it.

The remaining parts are the files of which there can be zero or more.
Each file part should contain the Content-ID MIME header through
which the JSON meta data’s files element addresses it. The value
should be the name of the file.

Content-Disposition is an optional MIME header. The header’s
optional filename parameter can be used to specify the file name
that Bitbucket should use when writing the file to disk. When present,
filename takes precedence over the value of Content-ID.

When the JSON body omits the files element, the remaining parts are
not ignored. Instead, each file is added to the new snippet as if its
name was explicitly linked (the use of the files elements is
mandatory for some operations like deleting or renaming files).

multipart/form-data

The use of JSON for the snippet’s meta data is optional. Meta data can
also be supplied as regular form fields in a more conventional
multipart/form-data request:

$ curl -X POST -u credentials https://api.bitbucket.org/2.0/snippets               -F title="My snippet"               -F file=@foo.txt -F file=@image.png

POST /2.0/snippets HTTP/1.1
Content-Length: 951
Content-Type: multipart/form-data; boundary=----------------------------63a4b224c59f

------------------------------63a4b224c59f
Content-Disposition: form-data; name="file"; filename="foo.txt"
Content-Type: text/plain

foo

------------------------------63a4b224c59f
Content-Disposition: form-data; name="file"; filename="image.png"
Content-Type: application/octet-stream

?PNG

IHDR?1??I.....
------------------------------63a4b224c59f
Content-Disposition: form-data; name="title"

My snippet
------------------------------63a4b224c59f--

Here the meta data properties are included as flat, top-level form
fields. The file attachments use the file field name. To attach
multiple files, simply repeat the field.

The advantage of multipart/form-data over multipart/related is
that it can be easier to build clients.

Essentially all properties are optional, title and files included.

Sharing and Visibility

Snippets can be either public (visible to anyone on Bitbucket, as well
as anonymous users), or private (visible only to members of the workspace).
This is controlled through the snippet’s is_private element:

  • is_private=false – everyone, including anonymous users can view
    the snippet
  • is_private=true – only workspace members can view the snippet

To create the snippet under a workspace, just append the workspace ID
to the URL. See /2.0/snippets/{workspace}.

operationId: Snippets_createSnippet

Request Body

The new snippet object.

application/json
schema snippet
Property Type Required
type string required
id integer optional
scm string optional
owner object optional
type string required
uuid string optional
links object optional
avatar object optional
href string optional
name string optional
username string optional
created_on string optional
display_name string optional
title string optional
creator object optional
type string required
uuid string optional
links object optional
avatar object optional
href string optional
name string optional
username string optional
created_on string optional
display_name string optional
created_on string optional
is_private boolean optional
updated_on string optional

Responses

201

The newly created snippet object.

401

If the request was not authenticated

POST /snippets
GET /snippets/{workspace}

Identical to /snippets, except that the result is further filtered
by the snippet owner and only those that are owned by {workspace} are
returned.

operationId: Snippets_listInWorkspace

Parameters

Name In Required Type Description
workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

role query optional string

Filter down the result based on the authenticated user’s role (owner, contributor, or member).

Responses

200

A paginated list of snippets.

404

If the user does not exist.

GET /snippets/{workspace}
POST /snippets/{workspace}

Identical to /snippets, except that the new snippet will be
created under the workspace specified in the path parameter
{workspace}.

operationId: Snippets_createForWorkspace

Parameters

Name In Required Type Description
workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Request Body

The new snippet object.

application/json
schema snippet
Property Type Required
type string required
id integer optional
scm string optional
owner object optional
type string required
uuid string optional
links object optional
avatar object optional
href string optional
name string optional
username string optional
created_on string optional
display_name string optional
title string optional
creator object optional
type string required
uuid string optional
links object optional
avatar object optional
href string optional
name string optional
username string optional
created_on string optional
display_name string optional
created_on string optional
is_private boolean optional
updated_on string optional

Responses

201

The newly created snippet object.

401

If the request was not authenticated

403

If the authenticated user does not have permission to create snippets in the specified workspace.

POST /snippets/{workspace}
DELETE /snippets/{workspace}/{encoded_id}

Deletes a snippet and returns an empty response.

operationId: Snippets_deleteSnippet

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

204

If the snippet was deleted successfully.

401

If the snippet is private and the request was not authenticated.

403

If authenticated user does not have permission to delete the private snippet.

404

If the snippet does not exist.

DELETE /snippets/{workspace}/{encoded_id}
GET /snippets/{workspace}/{encoded_id}

Retrieves a single snippet.

Snippets support multiple content types:

  • application/json
  • multipart/related
  • multipart/form-data

application/json

The default content type of the response is application/json.
Since JSON is always utf-8, it cannot reliably contain file contents
for files that are not text. Therefore, JSON snippet documents only
contain the filename and links to the file contents.

This means that in order to retrieve all parts of a snippet, N+1
requests need to be made (where N is the number of files in the
snippet).

multipart/related

To retrieve an entire snippet in a single response, use the
Accept: multipart/related HTTP request header.

$ curl -H "Accept: multipart/related" https://api.bitbucket.org/2.0/snippets/evzijst/1

Response:

HTTP/1.1 200 OK
Content-Length: 2214
Content-Type: multipart/related; start="snippet"; boundary="===============1438169132528273974=="
MIME-Version: 1.0

--===============1438169132528273974==
Content-Type: application/json; charset="utf-8"
MIME-Version: 1.0
Content-ID: snippet

{
  "links": {
    "self": {
      "href": "https://api.bitbucket.org/2.0/snippets/evzijst/kypj"
    },
    "html": {
      "href": "https://bitbucket.org/snippets/evzijst/kypj"
    },
    "comments": {
      "href": "https://api.bitbucket.org/2.0/snippets/evzijst/kypj/comments"
    },
    "watchers": {
      "href": "https://api.bitbucket.org/2.0/snippets/evzijst/kypj/watchers"
    },
    "commits": {
      "href": "https://api.bitbucket.org/2.0/snippets/evzijst/kypj/commits"
    }
  },
  "id": kypj,
  "title": "My snippet",
  "created_on": "2014-12-29T22:22:04.790331+00:00",
  "updated_on": "2014-12-29T22:22:04.790331+00:00",
  "is_private": false,
  "files": {
    "foo.txt": {
      "links": {
        "self": {
          "href": "https://api.bitbucket.org/2.0/snippets/evzijst/kypj/files/367ab19/foo.txt"
        },
        "html": {
          "href": "https://bitbucket.org/snippets/evzijst/kypj#file-foo.txt"
        }
      }
    },
    "image.png": {
      "links": {
        "self": {
          "href": "https://api.bitbucket.org/2.0/snippets/evzijst/kypj/files/367ab19/image.png"
        },
        "html": {
          "href": "https://bitbucket.org/snippets/evzijst/kypj#file-image.png"
        }
      }
    }
  ],
  "owner": {
    "username": "evzijst",
    "nickname": "evzijst",
    "display_name": "Erik van Zijst",
    "uuid": "{d301aafa-d676-4ee0-88be-962be7417567}",
    "links": {
      "self": {
        "href": "https://api.bitbucket.org/2.0/users/evzijst"
      },
      "html": {
        "href": "https://bitbucket.org/evzijst"
      },
      "avatar": {
        "href": "https://bitbucket-staging-assetroot.s3.amazonaws.com/c/photos/2013/Jul/31/erik-avatar-725122544-0_avatar.png"
      }
    }
  },
  "creator": {
    "username": "evzijst",
    "nickname": "evzijst",
    "display_name": "Erik van Zijst",
    "uuid": "{d301aafa-d676-4ee0-88be-962be7417567}",
    "links": {
      "self": {
        "href": "https://api.bitbucket.org/2.0/users/evzijst"
      },
      "html": {
        "href": "https://bitbucket.org/evzijst"
      },
      "avatar": {
        "href": "https://bitbucket-staging-assetroot.s3.amazonaws.com/c/photos/2013/Jul/31/erik-avatar-725122544-0_avatar.png"
      }
    }
  }
}

--===============1438169132528273974==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-ID: "foo.txt"
Content-Disposition: attachment; filename="foo.txt"

foo

--===============1438169132528273974==
Content-Type: image/png
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID: "image.png"
Content-Disposition: attachment; filename="image.png"

iVBORw0KGgoAAAANSUhEUgAAABQAAAAoCAYAAAD+MdrbAAABD0lEQVR4Ae3VMUoDQRTG8ccUaW2m
TKONFxArJYJamCvkCnZTaa+VnQdJSBFl2SMsLFrEWNjZBZs0JgiL/+KrhhVmJRbCLPx4O+/DT2TB
cbblJxf+UWFVVRNsEGAtgvJxnLm2H+A5RQ93uIl+3632PZyl/skjfOn9Gvdwmlcw5aPUwimG+NT5
EnNN036IaZePUuIcK533NVfal7/5yjWeot2z9ta1cAczHEf7I+3J0ws9Cgx0fsOFpmlfwKcWPuBQ
73Oc4FHzBaZ8llq4q1mr5B2mOUCt815qYR8eB1hG2VJ7j35q4RofaH7IG+Xrf/PfJhfmwtfFYoIN
AqxFUD6OMxcvkO+UfKfkOyXfKdsv/AYCHMLVkHAFWgAAAABJRU5ErkJggg==
--===============1438169132528273974==--

multipart/form-data

As with creating new snippets, multipart/form-data can be used as an
alternative to multipart/related. However, the inherently flat
structure of form-data means that only basic, root-level properties
can be returned, while nested elements like links are omitted:

$ curl -H "Accept: multipart/form-data" https://api.bitbucket.org/2.0/snippets/evzijst/kypj

Response:

HTTP/1.1 200 OK
Content-Length: 951
Content-Type: multipart/form-data; boundary=----------------------------63a4b224c59f

------------------------------63a4b224c59f
Content-Disposition: form-data; name="title"
Content-Type: text/plain; charset="utf-8"

My snippet
------------------------------63a4b224c59f--
Content-Disposition: attachment; name="file"; filename="foo.txt"
Content-Type: text/plain

foo

------------------------------63a4b224c59f
Content-Disposition: attachment; name="file"; filename="image.png"
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream

iVBORw0KGgoAAAANSUhEUgAAABQAAAAoCAYAAAD+MdrbAAABD0lEQVR4Ae3VMUoDQRTG8ccUaW2m
TKONFxArJYJamCvkCnZTaa+VnQdJSBFl2SMsLFrEWNjZBZs0JgiL/+KrhhVmJRbCLPx4O+/DT2TB
cbblJxf+UWFVVRNsEGAtgvJxnLm2H+A5RQ93uIl+3632PZyl/skjfOn9Gvdwmlcw5aPUwimG+NT5
EnNN036IaZePUuIcK533NVfal7/5yjWeot2z9ta1cAczHEf7I+3J0ws9Cgx0fsOFpmlfwKcWPuBQ
73Oc4FHzBaZ8llq4q1mr5B2mOUCt815qYR8eB1hG2VJ7j35q4RofaH7IG+Xrf/PfJhfmwtfFYoIN
AqxFUD6OMxcvkO+UfKfkOyXfKdsv/AYCHMLVkHAFWgAAAABJRU5ErkJggg==
------------------------------5957323a6b76--
operationId: Snippets_getSingleSnippet

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The snippet object.

401

If the snippet is private and the request was not authenticated.

403

If authenticated user does not have access to the private snippet.

404

If the snippet does not exist.

410

If the snippet marked as spam.

GET /snippets/{workspace}/{encoded_id}
PUT /snippets/{workspace}/{encoded_id}

Used to update a snippet. Use this to add and delete files and to
change a snippet’s title.

To update a snippet, one can either PUT a full snapshot, or only the
parts that need to be changed.

The contract for PUT on this API is that properties missing from the
request remain untouched so that snippets can be efficiently
manipulated with differential payloads.

To delete a property (e.g. the title, or a file), include its name in
the request, but omit its value (use null).

As in Git, explicit renaming of files is not supported. Instead, to
rename a file, delete it and add it again under another name. This can
be done atomically in a single request. Rename detection is left to
the SCM.

PUT supports three different content types for both request and
response bodies:

  • application/json
  • multipart/related
  • multipart/form-data

The content type used for the request body can be different than that
used for the response. Content types are specified using standard HTTP
headers.

Use the Content-Type and Accept headers to select the desired
request and response format.

application/json

As with creation and retrieval, the content type determines what
properties can be manipulated. application/json does not support
file contents and is therefore limited to a snippet’s meta data.

To update the title, without changing any of its files:

$ curl -X POST -H "Content-Type: application/json" https://api.bitbucket.org/2.0/snippets/evzijst/kypj             -d '{"title": "Updated title"}'

To delete the title:

$ curl -X POST -H "Content-Type: application/json" https://api.bitbucket.org/2.0/snippets/evzijst/kypj             -d '{"title": null}'

Not all parts of a snippet can be manipulated. The owner and creator
for instance are immutable.

multipart/related

multipart/related can be used to manipulate all of a snippet’s
properties. The body is identical to a POST. properties omitted from
the request are left unchanged. Since the start part contains JSON,
the mechanism for manipulating the snippet’s meta data is identical
to application/json requests.

To update one of a snippet’s file contents, while also changing its
title:

PUT /2.0/snippets/evzijst/kypj HTTP/1.1
Content-Length: 288
Content-Type: multipart/related; start="snippet"; boundary="===============1438169132528273974=="
MIME-Version: 1.0

--===============1438169132528273974==
Content-Type: application/json; charset="utf-8"
MIME-Version: 1.0
Content-ID: snippet

{
  "title": "My updated snippet",
  "files": {
      "foo.txt": {}
    }
}

--===============1438169132528273974==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-ID: "foo.txt"
Content-Disposition: attachment; filename="foo.txt"

Updated file contents.

--===============1438169132528273974==--

Here only the parts that are changed are included in the body. The
other files remain untouched.

Note the use of the files list in the JSON part. This list contains
the files that are being manipulated. This list should have
corresponding multiparts in the request that contain the new contents
of these files.

If a filename in the files list does not have a corresponding part,
it will be deleted from the snippet, as shown below:

PUT /2.0/snippets/evzijst/kypj HTTP/1.1
Content-Length: 188
Content-Type: multipart/related; start="snippet"; boundary="===============1438169132528273974=="
MIME-Version: 1.0

--===============1438169132528273974==
Content-Type: application/json; charset="utf-8"
MIME-Version: 1.0
Content-ID: snippet

{
  "files": {
    "image.png": {}
  }
}

--===============1438169132528273974==--

To simulate a rename, delete a file and add the same file under
another name:

PUT /2.0/snippets/evzijst/kypj HTTP/1.1
Content-Length: 212
Content-Type: multipart/related; start="snippet"; boundary="===============1438169132528273974=="
MIME-Version: 1.0

--===============1438169132528273974==
Content-Type: application/json; charset="utf-8"
MIME-Version: 1.0
Content-ID: snippet

{
    "files": {
      "foo.txt": {},
      "bar.txt": {}
    }
}

--===============1438169132528273974==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-ID: "bar.txt"
Content-Disposition: attachment; filename="bar.txt"

foo

--===============1438169132528273974==--

multipart/form-data

Again, one can also use multipart/form-data to manipulate file
contents and meta data atomically.

$ curl -X PUT http://localhost:12345/2.0/snippets/evzijst/kypj             -F title="My updated snippet" -F file=@foo.txt

PUT /2.0/snippets/evzijst/kypj HTTP/1.1
Content-Length: 351
Content-Type: multipart/form-data; boundary=----------------------------63a4b224c59f

------------------------------63a4b224c59f
Content-Disposition: form-data; name="file"; filename="foo.txt"
Content-Type: text/plain

foo

------------------------------63a4b224c59f
Content-Disposition: form-data; name="title"

My updated snippet
------------------------------63a4b224c59f

To delete a file, omit its contents while including its name in the
files field:

$ curl -X PUT https://api.bitbucket.org/2.0/snippets/evzijst/kypj -F files=image.png

PUT /2.0/snippets/evzijst/kypj HTTP/1.1
Content-Length: 149
Content-Type: multipart/form-data; boundary=----------------------------ef8871065a86

------------------------------ef8871065a86
Content-Disposition: form-data; name="files"

image.png
------------------------------ef8871065a86--

The explicit use of the files element in multipart/related and
multipart/form-data is only required when deleting files.
The default mode of operation is for file parts to be processed,
regardless of whether or not they are listed in files, as a
convenience to the client.

operationId: Snippets_updateSnippet

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The updated snippet object.

401

If the snippet is private and the request was not authenticated.

403

If authenticated user does not have permission to update the private snippet.

404

If the snippet does not exist.

PUT /snippets/{workspace}/{encoded_id}
GET /snippets/{workspace}/{encoded_id}/comments

Used to retrieve a paginated list of all comments for a specific
snippet.

This resource works identical to commit and pull request comments.

The default sorting is oldest to newest and can be overridden with
the sort query parameter.

operationId: Snippets_listComments

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

A paginated list of snippet comments, ordered by creation date.

403

If the authenticated user does not have access to the snippet.

404

If the snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/comments
POST /snippets/{workspace}/{encoded_id}/comments

Creates a new comment.

The only required field in the body is content.raw.

To create a threaded reply to an existing comment, include parent.id.

operationId: Snippets_createComment

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Request Body

required

The contents of the new comment.

application/json
schema snippet_comment
Property Type Required
type string required
links object optional
html object optional
href string optional
name string optional
self object optional
href string optional
name string optional
snippet object optional
type string required
id integer optional
scm string optional
owner object optional
type string required
uuid string optional
links object optional
avatar object optional
username string optional
created_on string optional
display_name string optional
title string optional
creator object optional
type string required
uuid string optional
links object optional
avatar object optional
username string optional
created_on string optional
display_name string optional
created_on string optional
is_private boolean optional
updated_on string optional

Responses

201

The newly created comment.

403

If the authenticated user does not have access to the snippet.

404

If the snippet does not exist.

POST /snippets/{workspace}/{encoded_id}/comments
DELETE /snippets/{workspace}/{encoded_id}/comments/{comment_id}

Deletes a snippet comment.

Comments can only be removed by the comment author, snippet creator, or workspace admin.

operationId: Snippets_deleteComment

Parameters

Name In Required Type Description
comment_id path required integer

The id of the comment.

encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

204

Indicates the comment was deleted successfully.

403

If the authenticated user is not the author of the comment.

404

If the comment or the snippet does not exist.

DELETE /snippets/{workspace}/{encoded_id}/comments/{comment_id}
GET /snippets/{workspace}/{encoded_id}/comments/{comment_id}

Returns the specific snippet comment.

operationId: Snippets_getComment

Parameters

Name In Required Type Description
comment_id path required integer

The id of the comment.

encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The specified comment.

403

If the authenticated user does not have access to the snippet.

404

If the comment or snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/comments/{comment_id}
PUT /snippets/{workspace}/{encoded_id}/comments/{comment_id}

Updates a comment.

The only required field in the body is content.raw.

Comments can only be updated by their author.

operationId: Snippets_updateComment

Parameters

Name In Required Type Description
comment_id path required integer

The id of the comment.

encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Request Body

required

The contents to update the comment to.

application/json
schema snippet_comment
Property Type Required
type string required
links object optional
html object optional
href string optional
name string optional
self object optional
href string optional
name string optional
snippet object optional
type string required
id integer optional
scm string optional
owner object optional
type string required
uuid string optional
links object optional
avatar object optional
username string optional
created_on string optional
display_name string optional
title string optional
creator object optional
type string required
uuid string optional
links object optional
avatar object optional
username string optional
created_on string optional
display_name string optional
created_on string optional
is_private boolean optional
updated_on string optional

Responses

200

The updated comment object.

403

If the authenticated user does not have access to the snippet.

404

If the comment or snippet does not exist.

PUT /snippets/{workspace}/{encoded_id}/comments/{comment_id}
GET /snippets/{workspace}/{encoded_id}/commits

Returns the changes (commits) made on this snippet.

operationId: Snippets_listChanges

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The paginated list of snippet commits.

403

If the authenticated user does not have access to the snippet.

404

If the snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/commits
GET /snippets/{workspace}/{encoded_id}/commits/{revision}

Returns the changes made on this snippet in this commit.

operationId: Snippets_getPreviousSnippetChange

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

revision path required string

The commit’s SHA1.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The specified snippet commit.

403

If the authenticated user does not have access to the snippet.

404

If the commit or the snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/commits/{revision}
GET /snippets/{workspace}/{encoded_id}/files/{path}

Convenience resource for getting to a snippet’s raw files without the
need for first having to retrieve the snippet itself and having to pull
out the versioned file links.

operationId: Snippets_getSnippetFileAtHead

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

path path required string

Path to the file.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

OK

302

A redirect to the most recent revision of the specified file.

403

If the authenticated user does not have access to the snippet.

404

If the snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/files/{path}
DELETE /snippets/{workspace}/{encoded_id}/watch

Used to stop watching a specific snippet. Returns 204 (No Content)
to indicate success.

operationId: Snippets_stopWatchingSnippet

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

204

Indicates the user stopped watching the snippet successfully.

401

If the request was not authenticated.

404

If the snippet does not exist.

DELETE /snippets/{workspace}/{encoded_id}/watch
GET /snippets/{workspace}/{encoded_id}/watch

Used to check if the current user is watching a specific snippet.

Returns 204 (No Content) if the user is watching the snippet and 404 if
not.

Hitting this endpoint anonymously always returns a 404.

operationId: Snippets_checkUserWatchingSnippet

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

204

If the authenticated user is watching the snippet.

404

If the snippet does not exist, or if the authenticated user is not watching the snippet.

GET /snippets/{workspace}/{encoded_id}/watch
PUT /snippets/{workspace}/{encoded_id}/watch

Used to start watching a specific snippet. Returns 204 (No Content).

operationId: Snippets_watchSnippet

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

204

Indicates the authenticated user is now watching the snippet.

401

If the request was not authenticated.

404

If the snippet does not exist.

PUT /snippets/{workspace}/{encoded_id}/watch
DELETE /snippets/{workspace}/{encoded_id}/{node_id}

Deletes the snippet.

Note that this only works for versioned URLs that point to the latest
commit of the snippet. Pointing to an older commit results in a 405
status code.

To delete a snippet, regardless of whether or not concurrent changes
are being made to it, use DELETE /snippets/{encoded_id} instead.

operationId: Snippets_deletePreviousRevision

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

node_id path required string

A commit revision (SHA1).

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

204

If the snippet was deleted successfully.

401

If the snippet is private and the request was not authenticated.

403

If authenticated user does not have permission to delete the private snippet.

404

If the snippet does not exist.

405

If {node_id} is not the latest revision.

DELETE /snippets/{workspace}/{encoded_id}/{node_id}
GET /snippets/{workspace}/{encoded_id}/{node_id}

Identical to GET /snippets/encoded_id, except that this endpoint
can be used to retrieve the contents of the snippet as it was at an
older revision, while /snippets/encoded_id always returns the
snippet’s current revision.

Note that only the snippet’s file contents are versioned, not its
meta data properties like the title.

Other than that, the two endpoints are identical in behavior.

operationId: Snippets_getPreviousRevision

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

node_id path required string

A commit revision (SHA1).

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The snippet object.

401

If the snippet is private and the request was not authenticated.

403

If authenticated user does not have access to the private snippet.

404

If the snippet, or the revision does not exist.

GET /snippets/{workspace}/{encoded_id}/{node_id}
PUT /snippets/{workspace}/{encoded_id}/{node_id}

Identical to UPDATE /snippets/encoded_id, except that this endpoint
takes an explicit commit revision. Only the snippet’s “HEAD”/”tip”
(most recent) version can be updated and requests on all other,
older revisions fail by returning a 405 status.

Usage of this endpoint over the unrestricted /snippets/encoded_id
could be desired if the caller wants to be sure no concurrent
modifications have taken place between the moment of the UPDATE
request and the original GET.

This can be considered a so-called “Compare And Swap”, or CAS
operation.

Other than that, the two endpoints are identical in behavior.

operationId: Snippets_updatePreviousRevision

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

node_id path required string

A commit revision (SHA1).

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The updated snippet object.

401

If the snippet is private and the request was not authenticated.

403

If authenticated user does not have permission to update the private snippet.

404

If the snippet or the revision does not exist.

405

If {node_id} is not the latest revision.

PUT /snippets/{workspace}/{encoded_id}/{node_id}
GET /snippets/{workspace}/{encoded_id}/{node_id}/files/{path}

Retrieves the raw contents of a specific file in the snippet. The
Content-Disposition header will be “attachment” to avoid issues with
malevolent executable files.

The file’s mime type is derived from its filename and returned in the
Content-Type header.

Note that for text files, no character encoding is included as part of
the content type.

operationId: Snippets_getRawFile

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

node_id path required string

A commit revision (SHA1).

path path required string

Path to the file.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

Returns the contents of the specified file.

403

If the authenticated user does not have access to the snippet.

404

If the file or snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/{node_id}/files/{path}
GET /snippets/{workspace}/{encoded_id}/{revision}/diff

Returns the diff of the specified commit against its first parent.

Note that this resource is different in functionality from the patch
resource.

The differences between a diff and a patch are:

  • patches have a commit header with the username, message, etc
  • diffs support the optional path=foo/bar.py query param to filter the
    diff to just that one file diff (not supported for patches)
  • for a merge, the diff will show the diff between the merge commit and
    its first parent (identical to how PRs work), while patch returns a
    response containing separate patches for each commit on the second
    parent’s ancestry, up to the oldest common ancestor (identical to
    its reachability).

Note that the character encoding of the contents of the diff is
unspecified as Git does not track this, making it hard for
Bitbucket to reliably determine this.

operationId: Snippets_getSnippetDiff

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

revision path required string

A revspec expression. This can simply be a commit SHA1, a ref name, or a compare expression like staging..production.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

path query optional string

When used, only one the diff of the specified file will be returned.

Responses

200

The raw diff contents.

403

If the authenticated user does not have access to the snippet.

404

If the snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/{revision}/diff
GET /snippets/{workspace}/{encoded_id}/{revision}/patch

Returns the patch of the specified commit against its first
parent.

Note that this resource is different in functionality from the diff
resource.

The differences between a diff and a patch are:

  • patches have a commit header with the username, message, etc
  • diffs support the optional path=foo/bar.py query param to filter the
    diff to just that one file diff (not supported for patches)
  • for a merge, the diff will show the diff between the merge commit and
    its first parent (identical to how PRs work), while patch returns a
    response containing separate patches for each commit on the second
    parent’s ancestry, up to the oldest common ancestor (identical to
    its reachability).

Note that the character encoding of the contents of the patch is
unspecified as Git does not track this, making it hard for
Bitbucket to reliably determine this.

operationId: Snippets_getSnippetPatch

Parameters

Name In Required Type Description
encoded_id path required string

The snippet id.

revision path required string

A revspec expression. This can simply be a commit SHA1, a ref name, or a compare expression like staging..production.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The raw patch contents.

403

If the authenticated user does not have access to the snippet.

404

If the snippet does not exist.

GET /snippets/{workspace}/{encoded_id}/{revision}/patch

Source 4 endpoints

GET /repositories/{workspace}/{repo_slug}/filehistory/{commit}/{path}

Returns a paginated list of commits that modified the specified file.

Commits are returned in reverse chronological order. This is roughly
equivalent to the following commands:

$ git log --follow --date-order <sha> <path>

By default, Bitbucket will follow renames and the path name in the
returned entries reflects that. This can be turned off using the
?renames=false query parameter.

Results are returned in descending chronological order by default, and
like most endpoints you can
filter and sort the response to
only provide exactly the data you want.

The example response returns commits made before 2011-05-18 against a file
named README.rst. The results are filtered to only return the path and
date. This request can be made using:

$ curl 'https://api.bitbucket.org/2.0/repositories/evzijst/dogslow/filehistory/master/README.rst'\
  '?fields=values.next,values.path,values.commit.date&q=commit.date<=2011-05-18'

In the response you can see that the file was renamed to README.rst
by the commit made on 2011-05-16, and was previously named README.txt.

operationId: Source_filehistoryListCommits

Parameters

Name In Required Type Description
commit path required string

The commit’s SHA1.

path path required string

Path to the file.

repo_slug path required string

This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

renames query optional string

When true, Bitbucket will follow the history of the file across
renames (this is the default behavior). This can be turned off by
specifying false.

q query optional string

Query string to narrow down the response as per
filtering and sorting.

sort query optional string

Name of a response property sort the result by as per
filtering and sorting.

Responses

200

A paginated list of commits that modified the specified file

404

If the repository does not exist.

GET /repositories/{workspace}/{repo_slug}/filehistory/{commit}/{path}
GET /repositories/{workspace}/{repo_slug}/src

This endpoint redirects the client to the directory listing of the
root directory on the main branch.

This is equivalent to directly hitting
/2.0/repositories/{username}/{repo_slug}/src/{commit}/{path}
without having to know the name or SHA1 of the repo’s main branch.

To create new commits, POST to this endpoint

operationId: Source_getRootDirectory

Parameters

Name In Required Type Description
repo_slug path required string

This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

format query optional string

Instead of returning the file’s contents, return the (json) meta data for it.

Responses

200

If the path matches a file, then the raw contents of the file are
returned (unless the format=meta query parameter was provided,
in which case a json document containing the file’s meta data is
returned). If the path matches a directory, then a paginated
list of file and directory entries is returned (if the
format=meta query parameter was provided, then the json document
containing the directory’s meta data is returned).

404

If the path or commit in the URL does not exist.

GET /repositories/{workspace}/{repo_slug}/src
POST /repositories/{workspace}/{repo_slug}/src

This endpoint is used to create new commits in the repository by
uploading files.

To add a new file to a repository:

$ curl https://api.bitbucket.org/2.0/repositories/username/slug/src \
  -F /repo/path/to/image.png=@image.png

This will create a new commit on top of the main branch, inheriting the
contents of the main branch, but adding (or overwriting) the
image.png file to the repository in the /repo/path/to directory.

To create a commit that deletes files, use the files parameter:

$ curl https://api.bitbucket.org/2.0/repositories/username/slug/src \
  -F files=/file/to/delete/1.txt \
  -F files=/file/to/delete/2.txt

You can add/modify/delete multiple files in a request. Rename/move a
file by deleting the old path and adding the content at the new path.

This endpoint accepts multipart/form-data (as in the examples above),
as well as application/x-www-form-urlencoded.

Note: multipart/form-data is currently not supported by Forge apps
for this API.

multipart/form-data

A multipart/form-data post contains a series of “form fields” that
identify both the individual files that are being uploaded, as well as
additional, optional meta data.

Files are uploaded in file form fields (those that have a
Content-Disposition parameter) whose field names point to the remote
path in the repository where the file should be stored. Path field
names are always interpreted to be absolute from the root of the
repository, regardless whether the client uses a leading slash (as the
above curl example did).

File contents are treated as bytes and are not decoded as text.

The commit message, as well as other non-file meta data for the
request, is sent along as normal form field elements. Meta data fields
share the same namespace as the file objects. For multipart/form-data
bodies that should not lead to any ambiguity, as the
Content-Disposition header will contain the filename parameter to
distinguish between a file named “message” and the commit message field.

application/x-www-form-urlencoded

It is also possible to upload new files using a simple
application/x-www-form-urlencoded POST. This can be convenient when
uploading pure text files:

$ curl https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src \
  --data-urlencode "/path/to/me.txt=Lorem ipsum." \
  --data-urlencode "message=Initial commit" \
  --data-urlencode "author=Erik van Zijst <erik.van.zijst@gmail.com>"

There could be a field name clash if a client were to upload a file
named “message”, as this filename clashes with the meta data property
for the commit message. To avoid this and to upload files whose names
clash with the meta data properties, use a leading slash for the files,
e.g. curl --data-urlencode "/message=file contents".

When an explicit slash is omitted for a file whose path matches that of
a meta data parameter, then it is interpreted as meta data, not as a
file.

Executables and links

While this API aims to facilitate the most common use cases, it is
possible to perform some more advanced operations like creating a new
symlink in the repository, or creating an executable file.

Files can be supplied with a x-attributes value in the
Content-Disposition header. For example, to upload an executable
file, as well as create a symlink from README.txt to README:

--===============1438169132528273974==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-ID: "bin/shutdown.sh"
Content-Disposition: attachment; filename="shutdown.sh"; x-attributes:"executable"

#!/bin/sh
halt

--===============1438169132528273974==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-ID: "/README.txt"
Content-Disposition: attachment; filename="README.txt"; x-attributes:"link"

README
--===============1438169132528273974==--

Links are files that contain the target path and have
x-attributes:"link" set.

When overwriting links with files, or vice versa, the newly uploaded
file determines both the new contents, as well as the attributes. That
means uploading a file without specifying x-attributes="link" will
create a regular file, even if the parent commit hosted a symlink at
the same path.

The same applies to executables. When modifying an existing executable
file, the form-data file element must include
x-attributes="executable" in order to preserve the executable status
of the file.

Note that this API does not support the creation or manipulation of
subrepos / submodules.

operationId: Source_createCommitByUploadingFile

Parameters

Name In Required Type Description
repo_slug path required string

This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

message query optional string

The commit message. When omitted, Bitbucket uses a canned string.

author query optional string

The raw string to be used as the new commit’s author.
This string follows the format
Erik van Zijst <evzijst@atlassian.com>.

When omitted, Bitbucket uses the authenticated user’s
full/display name and primary email address. Commits cannot
be created anonymously.

parents query optional string

A comma-separated list of SHA1s of the commits that should
be the parents of the newly created commit.

When omitted, the new commit will inherit from and become
a child of the main branch’s tip/HEAD commit.

When more than one SHA1 is provided, the first SHA1
identifies the commit from which the content will be
inherited.”.

files query optional string

Optional field that declares the files that the request is
manipulating. When adding a new file to a repo, or when
overwriting an existing file, the client can just upload
the full contents of the file in a normal form field and
the use of this files meta data field is redundant.
However, when the files field contains a file path that
does not have a corresponding, identically-named form
field, then Bitbucket interprets that as the client wanting
to replace the named file with the null set and the file is
deleted instead.

Paths in the repo that are referenced in neither files nor
an individual file field, remain unchanged and carry over
from the parent to the new commit.

This API does not support renaming as an explicit feature.
To rename a file, simply delete it and recreate it under
the new name in the same commit.

branch query optional string

The name of the branch that the new commit should be
created on. When omitted, the commit will be created on top
of the main branch and will become the main branch’s new
head.

When a branch name is provided that already exists in the
repo, then the commit will be created on top of that
branch. In this case, if a parent SHA1 was also provided,
then it is asserted that the parent is the branch’s
tip/HEAD at the time the request is made. When this is not
the case, a 409 is returned.

When a new branch name is specified (that does not already
exist in the repo), and no parent SHA1s are provided, then
the new commit will inherit from the current main branch’s
tip/HEAD commit, but not advance the main branch. The new
commit will be the new branch. When the request also
specifies a parent SHA1, then the new commit and branch
are created directly on top of the parent commit,
regardless of the state of the main branch.

When a branch name is not specified, but a parent SHA1 is
provided, then Bitbucket asserts that it represents the
main branch’s current HEAD/tip, or a 409 is returned.

When a branch name is not specified and the repo is empty,
the new commit will become the repo’s root commit and will
be on the main branch.

When a branch name is specified and the repo is empty, the
new commit will become the repo’s root commit and also
define the repo’s main branch going forward.

This API cannot be used to create additional root commits
in non-empty repos.

The branch field cannot be repeated.

As a side effect, this API can be used to create a new
branch without modifying any files, by specifying a new
branch name in this field, together with parents, but
omitting the files fields, while not sending any files.
This will create a new commit and branch with the same
contents as the first parent. The diff of this commit
against its first parent will be empty.

Responses

201
403

If the authenticated user does not have write or admin access

404

If the repository does not exist.

POST /repositories/{workspace}/{repo_slug}/src
GET /repositories/{workspace}/{repo_slug}/src/{commit}/{path}

This endpoints is used to retrieve the contents of a single file,
or the contents of a directory at a specified revision.

Raw file contents

When path points to a file, this endpoint returns the raw contents.
The response’s Content-Type is derived from the filename
extension (not from the contents). The file contents are not processed
and no character encoding/recoding is performed and as a result no
character encoding is included as part of the Content-Type.

The Content-Disposition header will be “attachment” to prevent
browsers from running executable files.

If the file is managed by LFS, then a 301 redirect pointing to
Atlassian’s media services platform is returned.

The response includes an ETag that is based on the contents of the file
and its attributes. This means that an empty __init__.py always
returns the same ETag, regardless on the directory it lives in, or the
commit it is on.

File meta data

When the request for a file path includes the query parameter
?format=meta, instead of returning the file’s raw contents, Bitbucket
instead returns the JSON object describing the file’s properties:

$ curl https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef/tests/__init__.py?format=meta
{
  "links": {
    "self": {
      "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py"
    },
    "meta": {
      "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py?format=meta"
    }
  },
  "path": "tests/__init__.py",
  "commit": {
    "type": "commit",
    "hash": "eefd5ef5d3df01aed629f650959d6706d54cd335",
    "links": {
      "self": {
        "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commit/eefd5ef5d3df01aed629f650959d6706d54cd335"
      },
      "html": {
        "href": "https://bitbucket.org/atlassian/bbql/commits/eefd5ef5d3df01aed629f650959d6706d54cd335"
      }
    }
  },
  "attributes": [],
  "type": "commit_file",
  "size": 0
}

File objects contain an attributes element that contains a list of
possible modifiers. Currently defined values are:

  • link – indicates that the entry is a symbolic link. The contents
    of the file represent the path the link points to.
  • executable – indicates that the file has the executable bit set.
  • subrepository – indicates that the entry points to a submodule or
    subrepo. The contents of the file is the SHA1 of the repository
    pointed to.
  • binary – indicates whether Bitbucket thinks the file is binary.

This endpoint can provide an alternative to how a HEAD request can be
used to check for the existence of a file, or a file’s size without
incurring the overhead of receiving its full contents.

Directory listings

When path points to a directory instead of a file, the response is a
paginated list of directory and file objects in the same order as the
underlying SCM system would return them.

For example:

$ curl https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef/tests
{
  "pagelen": 10,
  "values": [
    {
      "path": "tests/test_project",
      "type": "commit_directory",
      "links": {
        "self": {
          "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/"
        },
        "meta": {
          "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/?format=meta"
        }
      },
      "commit": {
        "type": "commit",
        "hash": "eefd5ef5d3df01aed629f650959d6706d54cd335",
        "links": {
          "self": {
            "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commit/eefd5ef5d3df01aed629f650959d6706d54cd335"
          },
          "html": {
            "href": "https://bitbucket.org/atlassian/bbql/commits/eefd5ef5d3df01aed629f650959d6706d54cd335"
          }
        }
      }
    },
    {
      "links": {
        "self": {
          "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py"
        },
        "meta": {
          "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py?format=meta"
        }
      },
      "path": "tests/__init__.py",
      "commit": {
        "type": "commit",
        "hash": "eefd5ef5d3df01aed629f650959d6706d54cd335",
        "links": {
          "self": {
            "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commit/eefd5ef5d3df01aed629f650959d6706d54cd335"
          },
          "html": {
            "href": "https://bitbucket.org/atlassian/bbql/commits/eefd5ef5d3df01aed629f650959d6706d54cd335"
          }
        }
      },
      "attributes": [],
      "type": "commit_file",
      "size": 0
    }
  ],
  "page": 1,
  "size": 2
}

When listing the contents of the repo’s root directory, the use of a
trailing slash at the end of the URL is required.

The response by default is not recursive, meaning that only the direct contents of
a path are returned. The response does not recurse down into
subdirectories. In order to “walk” the entire directory tree, the
client can either parse each response and follow the self links of each
commit_directory object, or can specify a max_depth to recurse to.

The max_depth parameter will do a breadth-first search to return the contents of the subdirectories
up to the depth specified. Breadth-first search was chosen as it leads to the least amount of
file system operations for git. If the max_depth parameter is specified to be too
large, the call will time out and return a 555.

Each returned object is either a commit_file, or a commit_directory,
both of which contain a path element. This path is the absolute path
from the root of the repository. Each object also contains a commit
object which embeds the commit the file is on. Note that this is merely
the commit that was used in the URL. It is not the commit that last
modified the file.

Directory objects have 2 representations. Their self link returns the
paginated contents of the directory. The meta link on the other hand
returns the actual directory object itself, e.g.:

{
  "path": "tests/test_project",
  "type": "commit_directory",
  "links": {
    "self": {
      "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/"
    },
    "meta": {
      "href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/?format=meta"
    }
  },
  "commit": { ... }
}

Querying, filtering and sorting

Like most API endpoints, this API supports the Bitbucket
querying/filtering syntax and so you could filter a directory listing
to only include entries that match certain criteria. For instance, to
list all binary files over 1kb use the expression:

size > 1024 and attributes = "binary"

which after urlencoding yields the query string:

?q=size%3E1024+and+attributes%3D%22binary%22

To change the ordering of the response, use the ?sort parameter:

.../src/eefd5ef/?sort=-size

See filtering and sorting for more
details.

operationId: Source_getRepositorySrcContent

Parameters

Name In Required Type Description
commit path required string

The commit’s SHA1.

path path required string

Path to the file.

repo_slug path required string

This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}.

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

format query optional string

If ‘meta’ is provided, returns the (json) meta data for the contents of the file. If ‘rendered’ is provided, returns the contents of a non-binary file in HTML-formatted rendered markup. The ‘rendered’ option only supports these filetypes: .md, .markdown, .mkd, .mkdn, .mdown, .text, .rst, and .textile. Since Git does not generally track what text encoding scheme is used, this endpoint attempts to detect the most appropriate character encoding. While usually correct, determining the character encoding can be ambiguous which in exceptional cases can lead to misinterpretation of the characters. As such, the raw element in the response object should not be treated as equivalent to the file’s actual contents.

q query optional string

Optional filter expression as per filtering and sorting.

sort query optional string

Optional sorting parameter as per filtering and sorting.

max_depth query optional integer

If provided, returns the contents of the repository and its subdirectories recursively until the specified max_depth of nested directories. When omitted, this defaults to 1.

Responses

200

If the path matches a file, then the raw contents of the file are
returned. If the format=meta query parameter is provided,
a json document containing the file’s meta data is
returned. If the format=rendered query parameter is provided,
the contents of the file in HTML-formated rendered markup is returned.
If the path matches a directory, then a paginated
list of file and directory entries is returned (if the
format=meta query parameter was provided, then the json document
containing the directory’s meta data is returned.)

404

If the path or commit in the URL does not exist.

555

If the call times out, possibly because the specified recursion depth is too large.

GET /repositories/{workspace}/{repo_slug}/src/{commit}/{path}

Ssh 5 endpoints

GET /users/{selected_user}/ssh-keys

Returns a paginated list of the user’s SSH public keys.

operationId: Ssh_listSshKeys

Parameters

Name In Required Type Description
selected_user path required string

This can either be an Atlassian Account ID OR the UUID of the account,
surrounded by curly-braces, for example: {account UUID}.

Responses

200

A list of the SSH keys associated with the account.

403

If the specified user’s keys are not accessible to the current user

404

If the specified user does not exist

GET /users/{selected_user}/ssh-keys
POST /users/{selected_user}/ssh-keys

Adds a new SSH public key to the specified user account and returns the resulting key.

Example:

$ curl -X POST -H "Content-Type: application/json" -d '{"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY user@myhost"}' https://api.bitbucket.org/2.0/users/{ed08f5e1-605b-4f4a-aee4-6c97628a673e}/ssh-keys
operationId: Ssh_keyAddition

Parameters

Name In Required Type Description
selected_user path required string

This can either be an Atlassian Account ID OR the UUID of the account,
surrounded by curly-braces, for example: {account UUID}.

Request Body

The new SSH key object. Note that the username property has been deprecated due to privacy changes.

application/json
schema ssh_account_key
Property Type Required
type string required
key string optional
uuid string optional
label string optional
links object optional
self object optional
href string optional
name string optional
comment string optional
last_used string optional
created_on string optional
owner object optional
type string required
uuid string optional
links object optional
avatar object optional
href string optional
name string optional
username string optional
created_on string optional
display_name string optional

Responses

201

The newly created SSH key.

400

If the submitted key or related value is invalid

403

If the current user does not have permission to add a key for the specified user

404

If the specified user does not exist

POST /users/{selected_user}/ssh-keys
DELETE /users/{selected_user}/ssh-keys/{key_id}

Deletes a specific SSH public key from a user’s account.

operationId: Ssh_deleteKey

Parameters

Name In Required Type Description
key_id path required string

The SSH key’s UUID value.

selected_user path required string

This can either be an Atlassian Account ID OR the UUID of the account,
surrounded by curly-braces, for example: {account UUID}.

Responses

204

The key has been deleted

400

If the submitted key or related value is invalid

403

If the current user does not have permission to add a key for the specified user

404

If the specified user does not exist

DELETE /users/{selected_user}/ssh-keys/{key_id}
GET /users/{selected_user}/ssh-keys/{key_id}

Returns a specific SSH public key belonging to a user.

operationId: Ssh_getKey

Parameters

Name In Required Type Description
key_id path required string

The SSH key’s UUID value.

selected_user path required string

This can either be an Atlassian Account ID OR the UUID of the account,
surrounded by curly-braces, for example: {account UUID}.

Responses

200

The specific SSH key matching the user and UUID

403

If the specified user or key is not accessible to the current user

404

If the specified user or key does not exist

GET /users/{selected_user}/ssh-keys/{key_id}
PUT /users/{selected_user}/ssh-keys/{key_id}

Updates a specific SSH public key on a user’s account

Note: Only the ‘comment’ field can be updated using this API. To modify the key or comment values, you must delete and add the key again.

Example:

$ curl -X PUT -H "Content-Type: application/json" -d '{"label": "Work key"}' https://api.bitbucket.org/2.0/users/{ed08f5e1-605b-4f4a-aee4-6c97628a673e}/ssh-keys/{b15b6026-9c02-4626-b4ad-b905f99f763a}
operationId: Ssh_updateSshKeyComment

Parameters

Name In Required Type Description
key_id path required string

The SSH key’s UUID value.

selected_user path required string

This can either be an Atlassian Account ID OR the UUID of the account,
surrounded by curly-braces, for example: {account UUID}.

Request Body

The updated SSH key object

application/json
schema ssh_account_key
Property Type Required
type string required
key string optional
uuid string optional
label string optional
links object optional
self object optional
href string optional
name string optional
comment string optional
last_used string optional
created_on string optional
owner object optional
type string required
uuid string optional
links object optional
avatar object optional
href string optional
name string optional
username string optional
created_on string optional
display_name string optional

Responses

200

The newly updated SSH key.

400

If the submitted key or related value is invalid

403

If the current user does not have permission to add a key for the specified user

404

If the specified user does not exist

PUT /users/{selected_user}/ssh-keys/{key_id}

Users 4 endpoints

GET /user

Returns the currently logged in user.

operationId: Users_getCurrentUser

Responses

200

The current user.

401

When the request wasn’t authenticated.

GET /user
GET /user/emails

Returns all the authenticated user’s email addresses. Both
confirmed and unconfirmed.

operationId: Users_listEmailAddresses

Responses

default

Unexpected error.

GET /user/emails
GET /user/emails/{email}

Returns details about a specific one of the authenticated user’s
email addresses.

Details describe whether the address has been confirmed by the user and
whether it is the user’s primary address or not.

operationId: Users_getEmailDetails

Parameters

Name In Required Type Description
email path required string

Email address of the user.

Responses

default

Unexpected error.

GET /user/emails/{email}
GET /users/{selected_user}

Gets the public information associated with a user account.

If the user’s profile is private, location, website and
created_on elements are omitted.

Note that the user object returned by this operation is changing significantly, due to privacy changes.
See the announcement for details.

operationId: Users_getUserDetails

Parameters

Name In Required Type Description
selected_user path required string

This can either be an Atlassian Account ID OR the UUID of the account,
surrounded by curly-braces, for example: {account UUID}.

Responses

200

The user object

404

If no user exists for the specified UUID, or if the specified account is a team account, not a personal account.

GET /users/{selected_user}

Webhooks 2 endpoints

GET /hook_events

Returns the webhook resource or subject types on which webhooks can
be registered.

Each resource/subject type contains an events link that returns the
paginated list of specific events each individual subject type can
emit.

This endpoint is publicly accessible and does not require
authentication or scopes.

operationId: Webhooks_getResourceEvents

Responses

200

A mapping of resource/subject types pointing to their individual event types.

GET /hook_events
GET /hook_events/{subject_type}

Returns a paginated list of all valid webhook events for the
specified entity.
The team and user webhooks are deprecated, and you should use workspace instead.
For more information, see the announcement.

This is public data that does not require any scopes or authentication.

NOTE: The example response is a truncated response object for the workspace subject_type.
We return the same structure for the other subject_type objects.

operationId: Webhooks_listSubscribableTypes

Parameters

Name In Required Type Description
subject_type path required string

A resource or subject type.

Responses

200

A paginated list of webhook types available to subscribe on.

404

If an invalid {subject_type} value was specified.

GET /hook_events/{subject_type}

Workspaces 7 endpoints

GET /user/permissions/workspaces

Returns an object for each workspace the caller is a member of, and
their effective role - the highest level of privilege the caller has.
If a user is a member of multiple groups with distinct roles, only the
highest level is returned.

Permissions can be:

  • owner
  • collaborator
  • member

The collaborator role is being removed from the Bitbucket Cloud API. For more information,
see the deprecation announcement.

When you move your administration from Bitbucket Cloud to admin.atlassian.com, the following fields on
workspace_membership will no longer be present: last_accessed and added_on. See the
deprecation announcement.

Results may be further filtered or sorted by
workspace or permission by adding the following query string parameters:

  • q=workspace.slug="bbworkspace1" or q=permission="owner"
  • sort=workspace.slug

Note that the query parameter values need to be URL escaped so that =
would become %3D.

operationId: Workspaces_listForCurrentUser

Parameters

Name In Required Type Description
q query optional string

Query string to narrow down the response. See
filtering and sorting for details.

sort query optional string

Name of a response property to sort results. See
filtering and sorting
for details.

Responses

200

All of the workspace memberships for the authenticated user.

401

The request wasn’t authenticated.

GET /user/permissions/workspaces
GET /workspaces

Returns a list of workspaces accessible by the authenticated user.

Results may be further filtered or sorted by
workspace or permission by adding the following query string parameters:

  • q=slug="bbworkspace1" or q=is_private=true
  • sort=created_on

Note that the query parameter values need to be URL escaped so that =
would become %3D.

The collaborator role is being removed from the Bitbucket Cloud API. For more information,
see the deprecation announcement.

operationId: Workspaces_listForUser

Parameters

Name In Required Type Description
role query optional string
        Filters the workspaces based on the authenticated user's role on each workspace.

        * **member**: returns a list of all the workspaces which the caller is a member of
            at least one workspace group or repository
        * **collaborator**: returns a list of workspaces which the caller has write access
            to at least one repository in the workspace
        * **owner**: returns a list of workspaces which the caller has administrator access
q query optional string

Query string to narrow down the response. See
filtering and sorting for details.

sort query optional string

Name of a response property to sort results. See
filtering and sorting
for details.

Responses

200

The list of workspaces accessible by the authenticated user.

401

The request wasn’t authenticated.

GET /workspaces
GET /workspaces/{workspace}

Returns the requested workspace.

operationId: Workspaces_getWorkspace

Parameters

Name In Required Type Description
workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The workspace.

404

If no workspace exists for the specified name or UUID.

GET /workspaces/{workspace}
GET /workspaces/{workspace}/hooks

Returns a paginated list of webhooks installed on this workspace.

operationId: Workspaces_listWebhooks

Parameters

Name In Required Type Description
workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The paginated list of installed webhooks.

403

If the authenticated user is not an owner on the specified workspace.

404

If the specified workspace does not exist.

GET /workspaces/{workspace}/hooks
POST /workspaces/{workspace}/hooks

Creates a new webhook on the specified workspace.

Workspace webhooks are fired for events from all repositories contained
by that workspace.

Example:

$ curl -X POST -u credentials -H 'Content-Type: application/json'
  https://api.bitbucket.org/2.0/workspaces/my-workspace/hooks
  -d '
    {
      "description": "Webhook Description",
      "url": "https://example.com/",
      "active": true,
      "secret": "this is a really bad secret",
      "events": [
        "repo:push",
        "issue:created",
        "issue:updated"
      ]
    }'

When the secret is provided it will be used as the key to generate a HMAC
digest value sent in the X-Hub-Signature header at delivery time. Passing
a null or empty secret or not passing a secret will leave the webhook’s
secret unset. Bitbucket only generates the X-Hub-Signature when the webhook’s
secret is set.

This call requires the webhook scope, as well as any scope
that applies to the events that the webhook subscribes to. In the
example above that means: webhook, repository and issue.

The url must properly resolve and cannot be an internal, non-routed address.

Only workspace owners can install webhooks on workspaces.

operationId: Workspaces_createWebhook

Parameters

Name In Required Type Description
workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

201

If the webhook was registered successfully.

403

If the authenticated user does not have permission to install webhooks on the specified workspace.

404

If the specified workspace does not exist.

POST /workspaces/{workspace}/hooks
DELETE /workspaces/{workspace}/hooks/{uid}

Deletes the specified webhook subscription from the given workspace.

operationId: Workspaces_deleteWebhook

Parameters

Name In Required Type Description
uid path required string

Installed webhook’s ID

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

204

When the webhook was deleted successfully

403

If the authenticated user does not have permission to delete the webhook.

404

If the webhook or workspace does not exist.

DELETE /workspaces/{workspace}/hooks/{uid}
GET /workspaces/{workspace}/hooks/{uid}

Returns the webhook with the specified id installed on the given
workspace.

operationId: Workspaces_getWorkspaceWebhook

Parameters

Name In Required Type Description
uid path required string

Installed webhook’s ID

workspace path required string

This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.

Responses

200

The webhook subscription object.

404

If the webhook or workspace does not exist.

GET /workspaces/{workspace}/hooks/{uid}
Load more endpoints