This is the reference document for the Atlassian Bitbucket REST API. The REST API is for developers who want to:
Because the REST API is based on open standards, you can use any web development language or command line tool capable of generating an HTTP request to access the API. See the developer documentation for a basic usage example.
If you're already working with the Atlassian SDK, the REST API Browser is a great tool for exploring and experimenting with the Bitbucket REST API.
Bitbucket's REST APIs provide access to resources (data entities) via URI paths. To use a REST API, your application will make an HTTP request and parse the response. The Bitbucket REST API uses JSON as its communication format, and the standard HTTP methods like GET, PUT, POST and DELETE. URIs for Bitbucket's REST API resource have the following structure:
http://host:port/context/rest/api-name/api-version/path/to/resource
For example, the following URI would retrieve a page of the latest commits to the jira repository in the JIRA project on https://stash.atlassian.com.
https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits
See the API descriptions below for a full list of available resources.
Alternatively we also publish a list of resources in WADL format. It is available here.
Bitbucket uses paging to conserve server resources and limit response size for resources that return potentially large
collections of items. A request to a paged API will result in a values
array wrapped in a JSON object
with some paging metadata, like this:
{ "size": 3, "limit": 3, "isLastPage": false, "values": [ { /* result 0 */ }, { /* result 1 */ }, { /* result 2 */ } ], "start": 0, "filter": null, "nextPageStart": 3 }
Clients can use the limit
and start
query parameters to retrieve the desired number of
results.
The limit
parameter indicates how many results to return per page. Most APIs default to returning
25
if the limit is left unspecified. This number can be increased, but note that a resource-specific
hard limit will apply. These hard limits can be configured by server administrators, so it's always best practice to
check the limit
attribute on the response to see what limit has been applied.
The request to get a larger page should look like this:
http://host:port/context/rest/api-name/api-version/path/to/resource?limit={desired size of page}
For example:
https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?limit=1000
The start
parameter indicates which item should be used as the first item in the page of results. All
paged responses contain an isLastPage
attribute indicating whether another page of items exists.
Important: If more than one page exists (i.e. the response contains
"isLastPage": false
), the response object will also contain a nextPageStart
attribute
which must be used by the client as the start
parameter on the next request.
Identifiers of adjacent objects in a page may not be contiguous, so the start of the next page is not
necessarily the start of the last page plus the last page's size. A client should always use
nextPageStart
to avoid unexpected results from a paged API.
The request to get a subsequent page should look like this:
http://host:port/context/rest/api-name/api-version/path/to/resource?start={nextPageStart from previous response}
For example:
https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?start=25
Any authentication that works against Bitbucket will work against the REST API. The preferred authentication methods are HTTP Basic (when using SSL) and OAuth. Other supported methods include: HTTP Cookies and Trusted Applications.
You can find OAuth code samples in several programming languages at bitbucket.org/atlassian_tutorial/atlassian-oauth-examples.
The log-in page uses cookie-based authentication, so if you are using Bitbucket in a browser you can call REST from JavaScript on the page and rely on the authentication that the browser has established.
If a request fails due to client error, the resource will return an HTTP response code in the 40x range. These can be broadly categorised into:
HTTP Code | Description |
---|---|
400 (Bad Request) |
One or more of the required parameters or attributes:
|
401 (Unauthorized) |
Either:
|
403 (Forbidden) | Actions are usually "forbidden" if they involve breaching the licensed user limit of the server, or degrading the authenticated user's permission level. See the individual resource documentation for more details. |
404 (Not Found) | The entity you are attempting to access, or the project or repository containing it, does not exist. |
405 (Method Not Allowed) | The request HTTP method is not appropriate for the targeted resource. For example an HTTP GET to a resource that only accepts an HTTP POST will result in a 405. |
409 (Conflict) |
The attempted update failed due to some conflict with an existing resource. For example:
|
415 (Unsupported Media Type) |
The request entity has a Content-Type that the server does not support. Almost all of the
Bitbucket REST API accepts application/json format, but check the individual resource
documentation for more details. Additionally, double-check that you are setting the
Content-Type header correctly on your request (e.g. using
-H "Content-Type: application/json" in cURL).
|
For 400 HTTP codes the response will typically contain one or more validation error messages, for example:
{ "errors": [ { "context": "name", "message": "The name should be between 1 and 255 characters.", "exceptionName": null }, { "context": "email", "message": "The email should be a valid email address.", "exceptionName": null } ] }
The context
attribute indicates which parameter or request entity attribute failed validation. Note
that the context
may be null.
For 401, 403, 404 and 409 HTTP codes, the response will contain one or more descriptive error messages:
{ "errors": [ { "context": null, "message": "A detailed error message.", "exceptionName": null } ] }
A 500 (Server Error) HTTP code indicates an incorrect resource url or an unexpected server error. Double-check the URL you are trying to access, then report the issue to your server administrator or Atlassian Support if problems persist.
Bitbucket allows users to manage their own repositories, called personal repositories. These are repositories associated with the user and to which they always have REPO_ADMIN permission.
Accessing personal repositories via REST is achieved through the normal project-centric REST URLs using the user's slug prefixed by tilde as the project key. E.g. to list personal repositories for a user with slug "johnsmith" you would make a GET to:
http://example.com/rest/api/1.0/projects/~johnsmith/repos
In addition to this, Bitbucket allows access to these repositories through an alternate set of user-centric REST URLs beginning with:
http://example.com/rest/api/1.0/users/~{userSlug}/reposE.g. to list the forks of the repository with slug "nodejs" in the personal project of user with slug "johnsmith" using the regular REST URL you would make a GET to:
http://example.com/rest/api/1.0/projects/~johnsmith/repos/nodejs/forksUsing the alternate URL, you would make a GET to:
http://example.com/rest/api/1.0/users/johnsmith/repos/nodejs/forks
Provides SSH support
This is a paged API.
Retrieves the access keys for the repository identified in the URL.
parameter | value | description |
---|---|---|
filter | if specified only SSH access keys with a label prefixed with the supplied string will be returned | |
effective | Default: false | Controls whether SSH access keys configured at the project level should be included in the
results or not. When set to |
permission | if specified only SSH access keys with at least the supplied permission will be returned
Default is |
Example response representations:
{"size":1,"limit":25,"isLastPage":true,"values":[{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"repository":{"slug":"my-repo","id":1,"name":"My repo","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"public":true,"links":{"clone":[{"href":"ssh://git@<baseURL>/PRJ/my-repo.git","name":"ssh"},{"href":"https://<baseURL>/scm/PRJ/my-repo.git","name":"http"}],"self":[{"href":"http://link/to/repository"}]}},"permission":"REPO_WRITE"}],"start":0}
A single page of access keys for the repository.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to retrieve the access keys for this repository
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified repository does not exist
Register a new SSH key and grants access to the repository identified in the URL.
Example request representations:
{"key":{"text":"ssh-rsa AAAAB3... me@127.0.0.1"},"permission":"REPO_WRITE"}
Example response representations:
{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"repository":{"slug":"my-repo","id":1,"name":"My repo","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"public":true,"links":{"clone":[{"href":"ssh://git@<baseURL>/PRJ/my-repo.git","name":"ssh"},{"href":"https://<baseURL>/scm/PRJ/my-repo.git","name":"http"}],"self":[{"href":"http://link/to/repository"}]}},"permission":"REPO_WRITE"}
The newly created access key
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The current request contains invalid or missing values.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to add an access key to the repository
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified repository does not exist
parameter | value | description |
---|---|---|
keyId | the identifier of the SSH key |
This is a paged API.
Retrieves the access keys for the repository identified in the URL.
Example response representations:
{"size":1,"limit":25,"isLastPage":true,"values":[{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"repository":{"slug":"my-repo","id":1,"name":"My repo","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"public":true,"links":{"clone":[{"href":"ssh://git@<baseURL>/PRJ/my-repo.git","name":"ssh"},{"href":"https://<baseURL>/scm/PRJ/my-repo.git","name":"http"}],"self":[{"href":"http://link/to/repository"}]}},"permission":"REPO_WRITE"}],"start":0}
A single page of access keys for the repository.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to retrieve the access keys for this repository
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified repository does not exist
Remove an existing access key for the repository identified in the URL. If the same SSH key is used as an access key for multiple projects or repositories, only the access to the repository identified in the URL will be revoked.
Example response representations:
The access key was deleted (or none was found matching the given id).
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to remove access keys for this repository
parameter | value | description |
---|---|---|
keyId |
This is a paged API.
Retrieves all project-related access keys for the SSH key with id keyId
. If the current user is not an
admin any of the projects the key provides access to, none are returned.
Example response representations:
the SSH key with ID keyId
.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified key does not exist
parameter | value | description |
---|---|---|
keyId |
This is a paged API.
Retrieves all repository-related access keys for the SSH key with id keyId
. If the current user is not
an admin of any of the projects the key provides access to, none are returned.
Example response representations:
the SSH key with ID keyId
.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified key does not exist
parameter | value | description |
---|---|---|
keyId |
Remove an existing access key for the project identified in the URL. If the same SSH key is used as an access key for multiple projects or repositories, only the access to the project identified in the URL will be revoked.
Example response representations:
The access key was deleted (or none was found matching the given id).
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to remove access keys for this project
This is a paged API.
Retrieves the access keys for the project identified in the URL.
Example response representations:
{"size":1,"limit":25,"isLastPage":true,"values":[{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"permission":"PROJECT_READ"}],"start":0}
A single page of access keys associated with the project.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to retrieve the access keys for this project
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified project does not exist
parameter | value | description |
---|---|---|
keyId | the SSH key ID | |
permission | the new permission to be granted to the SSH key |
Updates the permission granted to the specified SSH key to the project identified in the URL.
Example response representations:
{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"permission":"PROJECT_READ"}
The newly created access key
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions on the project to edit its access keys
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified project does not exist
parameter | value | description |
---|---|---|
keyId | the SSH key ID | |
permission | the new permission to be granted to the SSH key |
Updates the permission granted to the specified SSH key to the project identified in the URL.
Example response representations:
{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"permission":"PROJECT_READ"}
The newly created access key
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions on the project to edit its access keys
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified project does not exist
Register a new SSH key and grants access to the project identified in the URL.
Example request representations:
{"key":{"text":"ssh-rsa AAAAB3... me@127.0.0.1"},"permission":"PROJECT_READ"}
Example response representations:
{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"permission":"PROJECT_READ"}
The newly created access key
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The current request contains invalid or missing values.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to add an access key to the project.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified project does not exist
This is a paged API.
Retrieves the access keys for the project identified in the URL.
parameter | value | description |
---|---|---|
filter | if specified only SSH access keys with a label prefixed with the supplied string will be returned | |
permission | if specified only SSH access keys with at least the supplied permission will be returned Default is {@link Permission#PROJECT_READ}. |
Example response representations:
{"size":1,"limit":25,"isLastPage":true,"values":[{"key":{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"},"project":{"key":"PRJ","id":1,"name":"My Cool Project","description":"The description for my cool project.","public":true,"type":"NORMAL","links":{"self":[{"href":"http://link/to/project"}]}},"permission":"PROJECT_READ"}],"start":0}
A single page of access keys associated with the project.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to retrieve the access keys for this project
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The specified project does not exist
parameter | value | description |
---|---|---|
keyId | the identifier of the SSH key |
Remove an existing access key for the projects and repositories in the submitted entity. If the same SSH key is used as an access key for multiple projects or repositories not supplied, only the access to the projects or repositories identified will be revoked.
Example request representations:
Example response representations:
The access keys were deleted (or none was found matching the given id and repositories or projects).
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to remove access keys for one or more of the specified projects or repositories
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
On or more of the specified repositories or projects does not exist or the key itself does not exist
Add a new ssh key to a supplied user.
parameter | value | description |
---|---|---|
user | the username of the user to add the ssh key for. If no username is specified, the ssh key will be added for the current authenticated user. |
Example request representations:
{"text":"ssh-rsa AAAAB3... me@127.0.0.1"}
Example response representations:
{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"}
The newly created ssh key.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The ssh key was not created because the key was not a valid RSA/DSA/ECDSA/Ed25519 key of a supported length.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
Either there is no authenticated user or the currently authenticated user has insufficient permissions to add an ssh key. The latter is only possible when a user is explicitly supplied.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
No user matches the supplied user
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The ssh key already exists on the system.
This is a paged API.
Retrieve a page of ssh keys.
parameter | value | description |
---|---|---|
user | the username of the user to retrieve the keys for. If no username is specified, the ssh keys will be retrieved for the current authenticated user. |
Example response representations:
{"size":1,"limit":25,"isLastPage":true,"values":[{"id":1,"text":"ssh-rsa AAAAB3... me@127.0.0.1","label":"me@127.0.0.1"}],"start":0}
A page of ssh keys.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to retrieve the ssh keys. This is only possible when a user is explicitly supplied.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
No user matches the supplied user
Delete all ssh keys for a supplied user.
parameter | value | description |
---|---|---|
user | the username of the user to delete the keys for. If no username is specified, the ssh keys will be deleted for the current authenticated user. |
Example response representations:
The ssh keys matching the supplied user were deleted.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to delete the ssh keys. This is only possible when a user is explicitly supplied.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
No user matches the supplied user
parameter | value | description |
---|---|---|
keyId | the id of the key to delete. |
Delete an ssh key.
Example response representations:
The ssh key matching the supplied id was deleted or did not exist.
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The currently authenticated user has insufficient permissions to delete the ssh key.
Example response representations:
{"accessKeys":{"enabled":true},"baseUrl":"ssh://example.com","enabled":true,"fingerprint":{"algorithm":"RSA","value":"1BE9A09D47279BF92501DEB9A3D8717D"},"port":7999}
The ssh settings from upstream
{"errors":[{"context":null,"message":"A detailed error message.","exceptionName":null}]}
The request was not authenticated