atlassian-cli is an independent, community open-source project, not affiliated with, endorsed by, or sponsored by Atlassian, and is not Atlassian's official CLI (acli). Product names are used only to identify compatibility.
What Is the Bitbucket REST API?
The Bitbucket REST API is the HTTP interface Atlassian exposes for automating Bitbucket Cloud: creating repositories, opening and merging pull requests, triggering pipelines, managing branch permissions, and reading commits. The current version is 2.0, and every endpoint lives under a single base URL: https://api.bitbucket.org/2.0/. Requests are ordinary HTTPS calls, and responses come back as JSON, so anything that can send an authenticated GET or POST (curl, a Python script, a CI job) can drive Bitbucket.
The API is organized around a few nouns. A workspace groups your repositories, a repository is identified by a slug, and resources like pull requests and pipelines hang off a repository. A typical path reads left to right: /2.0/repositories/{workspace}/{repo_slug}/pullrequests. Once you know that shape, most of the API is discoverable by swapping the last segment.
This guide walks through authentication, the endpoints you will actually reach for, how pagination and rate limits work, and how to avoid writing the same curl-and-jq plumbing every time by putting a command-line wrapper in front of the API.
How this differs from official tooling: atlassian-cli is an independent, community, MIT-licensed open-source project. It is not Atlassian's official CLI (acli) and is not affiliated with, endorsed by, or sponsored by Atlassian. Use the official acli for first-party vendor support. Use atlassian-cli if you want a single free Rust binary that wraps the Bitbucket REST API alongside Jira, Confluence, and JSM.
Authentication Options
Every request to the Bitbucket REST API must be authenticated. Bitbucket Cloud supports several methods, and which one you pick depends on whether you are running a quick script or a long-lived automation.
- App passwords (HTTP Basic auth). An app password is a scoped credential tied to your account that you pass as the password in Basic auth. It is the simplest option for scripts and works with
curl -u "username:app_password". - Access tokens. Repository, project, and workspace access tokens are scoped to a single resource rather than your whole account. They are the safer default for automation because you can grant narrow permissions and revoke a token without changing your password.
- OAuth 2.0. For applications acting on behalf of other users, register an OAuth consumer and exchange it for a bearer token. This is the right path when you are building an integration rather than a personal script.
For the examples below, store your credential in an environment variable so it never lands in shell history or a committed file:
# Export a Basic-auth credential for the current shell session
export BB_USER="your-bitbucket-username"
export BB_APP_PASSWORD="your-app-password"
With an access token instead, you send it as a bearer token: -H "Authorization: Bearer $BB_TOKEN". The endpoints are identical; only the auth header changes.
Core REST 2.0 Endpoints
You do not need to memorize the whole API. In practice, a handful of endpoints cover the vast majority of automation. Here are the ones worth knowing, all relative to https://api.bitbucket.org/2.0/:
| Method & Path | What it does |
|---|---|
GET /user |
Returns the authenticated account. A quick way to verify your credential works. |
GET /workspaces/{workspace} |
Details for a workspace, including its slug and membership settings. |
GET /repositories/{workspace} |
Lists repositories in a workspace. Paginated. |
GET /repositories/{workspace}/{repo} |
Details for one repository. |
GET /repositories/{workspace}/{repo}/refs/branches |
Lists branches for a repository. |
GET /repositories/{workspace}/{repo}/pullrequests |
Lists pull requests. Filter with the state query parameter. |
POST /repositories/{workspace}/{repo}/pullrequests |
Creates a pull request from a source branch to a destination. |
POST .../pullrequests/{id}/approve |
Approves a pull request. |
POST .../pullrequests/{id}/merge |
Merges a pull request with a chosen strategy. |
GET /repositories/{workspace}/{repo}/pipelines/ |
Lists pipeline runs for a repository. |
POST /repositories/{workspace}/{repo}/pipelines/ |
Triggers a pipeline for a branch or commit. |
GET /repositories/{workspace}/{repo}/commits |
Lists commits, optionally scoped to a branch. |
Making Requests With curl
The fastest way to learn the API is to hit it directly. Start with a read that confirms your credential and shows you the JSON shape:
# List the first 10 repositories in a workspace
curl -s -u "$BB_USER:$BB_APP_PASSWORD" \
"https://api.bitbucket.org/2.0/repositories/myteam?pagelen=10"
Reads are safe to experiment with. Writes are where the API earns its keep. Creating a pull request is a POST with a small JSON body describing the source and destination branches:
# Open a pull request from feature/new into main
curl -s -u "$BB_USER:$BB_APP_PASSWORD" \
-X POST \
-H "Content-Type: application/json" \
"https://api.bitbucket.org/2.0/repositories/myteam/api-service/pullrequests" \
-d '{
"title": "Add feature",
"source": { "branch": { "name": "feature/new" } },
"destination": { "branch": { "name": "main" } }
}'
Triggering a pipeline follows the same pattern. The body tells Bitbucket which ref to build:
# Trigger the default pipeline on the main branch
curl -s -u "$BB_USER:$BB_APP_PASSWORD" \
-X POST \
-H "Content-Type: application/json" \
"https://api.bitbucket.org/2.0/repositories/myteam/api-service/pipelines/" \
-d '{
"target": {
"type": "pipeline_ref_target",
"ref_type": "branch",
"ref_name": "main"
}
}'
These three requests (list, create PR, trigger pipeline) are representative of the whole API. Most other operations are a variation on the same theme: a path built from workspace and repo, a method, and a JSON body. The friction shows up around the edges: encoding query parameters, following pagination, parsing JSON out of every response, and retrying when you get throttled.
Pagination and Rate Limits
Two behaviors trip people up when they script against the Bitbucket REST API directly.
Pagination. Collection endpoints do not return every result at once. They return a page object shaped like this:
{
"pagelen": 10,
"page": 1,
"values": [ /* repositories, PRs, commits... */ ],
"next": "https://api.bitbucket.org/2.0/repositories/myteam?page=2"
}
To read the full result set, you follow the next URL until the field disappears. You can request bigger pages with the pagelen query parameter to cut the number of round trips. Any script that only reads the first page silently misses data, which is a common and hard-to-spot bug.
Rate limits. Bitbucket enforces per-hour rate limits and returns an HTTP 429 when you exceed them. A robust client has to detect that status and back off before retrying, otherwise a large batch will start failing partway through. Getting pagination and backoff right is most of the work in a good Bitbucket client, and it is exactly the boilerplate a wrapper removes.
Wrapping the API With a CLI
If you are reaching for the Bitbucket REST API repeatedly, a command-line wrapper turns each of those curl blocks into a single line. atlassian-cli maps the REST 2.0 endpoints above to short commands, and it handles authentication, pagination, and 429 backoff internally so you get complete results without writing the plumbing.
Authenticate once, then call the API by intent instead of URL. See the authentication guide for the full setup:
# Store credentials in a named profile
atlassian-cli auth login \
--profile work \
--base-url https://your-workspace.atlassian.net \
--email you@example.com \
--token $TOKEN \
--default
# Confirm the Bitbucket credential resolves
atlassian-cli bitbucket whoami
From there, the same operations you wrote by hand become one-liners. Listing repositories walks every page for you:
# List repositories in a workspace (pagination handled automatically)
atlassian-cli bitbucket --workspace myteam repo list --limit 10
# Machine-readable output for scripting
atlassian-cli bitbucket --workspace myteam repo list --format json | jq '.[].slug'
Opening a pull request no longer needs a hand-built JSON body:
# Create a PR from feature/new into main
atlassian-cli bitbucket --workspace myteam pr create api-service \
--title "Add feature" \
--source feature/new \
--destination main
# Approve and merge it
atlassian-cli bitbucket --workspace myteam pr approve api-service 123
atlassian-cli bitbucket --workspace myteam pr merge api-service 123 --strategy merge_commit
Triggering a pipeline collapses the earlier POST into its arguments, including named custom pipelines defined in bitbucket-pipelines.yml:
# Trigger the pipeline on main
atlassian-cli bitbucket --workspace myteam pipeline trigger api-service --ref-name main
# Trigger a named custom pipeline
atlassian-cli bitbucket --workspace myteam pipeline trigger api-service \
--ref-name main --custom-pipeline s3-access-test
Every command accepts the global --format json|csv|yaml flag, so you can pipe results into jq, a spreadsheet, or another tool without parsing raw HTTP responses. The bb alias is interchangeable with bitbucket if you want to type less.
Try atlassian-cli
A single free binary that wraps the Bitbucket REST API alongside Jira, Confluence, and JSM. Independent and MIT-licensed.
Install atlassian-cliMapping Endpoints to CLI Commands
If you already know the REST endpoint you need, this table shows the equivalent atlassian-cli command. It is a useful bridge when you are porting an existing curl script to the CLI. The full list is in the command reference.
| REST 2.0 endpoint | atlassian-cli command |
|---|---|
GET /repositories/{ws} |
bitbucket --workspace ws repo list |
GET /repositories/{ws}/{repo} |
bitbucket --workspace ws repo get repo |
GET /repositories/{ws}/{repo}/refs/branches |
bitbucket --workspace ws branch list repo |
GET .../pullrequests?state=OPEN |
bitbucket --workspace ws pr list repo --state OPEN |
POST .../pullrequests |
bitbucket --workspace ws pr create repo --title ... --source ... --destination ... |
POST .../pullrequests/{id}/merge |
bitbucket --workspace ws pr merge repo 123 --strategy merge_commit |
POST .../pipelines/ |
bitbucket --workspace ws pipeline trigger repo --ref-name main |
GET .../commits |
bitbucket --workspace ws commit list repo --branch main |
For repeatable workflows built on these commands, the Bitbucket PR automation runbook shows a complete review-and-merge script, and the Bitbucket CLI guide covers day-to-day usage in more depth. Sibling walkthroughs on calling the Bitbucket API from the CLI and the full Bitbucket CLI command list go further on each area.
FAQ
What is the base URL for the Bitbucket REST API?
The current Bitbucket Cloud REST API is version 2.0, and every endpoint lives under https://api.bitbucket.org/2.0/. For example, listing repositories in a workspace is a GET request to https://api.bitbucket.org/2.0/repositories/{workspace}. All responses are JSON, and collection endpoints are paginated.
How do I authenticate with the Bitbucket API?
Bitbucket Cloud supports OAuth 2.0, app passwords used with HTTP Basic authentication, and access tokens scoped to a repository, project, or workspace. For quick scripts, an app password with Basic auth is the simplest: pass it with curl -u "username:app_password". For automation, prefer a scoped access token so you can limit and revoke access without touching your account password.
Does the Bitbucket REST API have rate limits?
Yes. Bitbucket enforces per-hour rate limits and returns an HTTP 429 status when you exceed them. When you script against the API directly, you need to detect 429 responses and back off before retrying. atlassian-cli handles this for you with automatic backoff, so bulk operations keep running without manual retries.
How is the Bitbucket REST API paginated?
Collection endpoints return a paginated object with a values array plus page, pagelen, and next fields. To read every result you follow the next URL until it disappears. You can request larger pages with the pagelen query parameter. A CLI wrapper like atlassian-cli walks these pages automatically so you get the full result set from a single command.
Can I use a CLI instead of calling the Bitbucket REST API directly?
Yes. atlassian-cli is an independent open-source wrapper that maps common REST 2.0 endpoints to short commands for repositories, branches, pull requests, pipelines, and permissions. It handles authentication, pagination, and rate limiting so you do not have to write curl and jq pipelines by hand. It is not Atlassian's official CLI (acli).