---
title: "Bitbucket API: Boost Your GIT DevOps Productivity"
description: "Discover how the Bitbucket API can elevate your GIT DevOps workflow. Join our tutorial for expert insights and practical applications to enhance productivity."
canonical: "https://adamtheautomator.com/bitbucket-api/"
---

# Bitbucket API: Boost Your GIT DevOps Productivity

> Discover how the Bitbucket API can elevate your GIT DevOps workflow. Join our tutorial for expert insights and practical applications to enhance productivity.

Source: https://adamtheautomator.com/bitbucket-api/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Bitbucket API: Boost Your GIT DevOps Productivity](https://adamtheautomator.com/wp-content/uploads/2022/12/bitbucket-api.jpg)

# Bitbucket API: Boost Your GIT DevOps Productivity

[![](https://secure.gravatar.com/avatar/a3e6f24b6b657f0acd2615f1802513a18663dea2e04d24e1df9c1530290e9b48?s=192&d=mm&r=g)Uzma Younas](https://adamtheautomator.com/author/uzma-younas/)22 January 20248 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[APIs](/tag/apis/)[Git](/tag/git/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Authenticating Bitbucket with an App Password](#authenticating-bitbucket-with-an-app-password)
*   [Authenticating Bitbucket via OAuth 2.0](#authenticating-bitbucket-via-oauth-20)
*   [Creating a Git Repository to Interact with Bitbucket API](#creating-a-git-repository-to-interact-with-bitbucket-api)
*   [Creating a User Group and Adding Users](#creating-a-user-group-and-adding-users)
*   [Listing All Pull Requests](#listing-all-pull-requests)
*   [Reviewing and Responding to Commits (Approve/Unapprove)](#reviewing-and-responding-to-commits-approveunapprove)
*   [Deleting Groups and Repositories](#deleting-groups-and-repositories)
*   [Conclusion](#conclusion)

Developers like yourself have a lot on their plate and typically need a common place to plan, collaborate, test, and deploy codes. Save yourself the frustration; consider the Bitbucket API to ease the management of your Bitbucket environment!

The Bitbucket API lets you automate setting up authentication, creating repositories, managing user groups, and pull requests. And in this tutorial, you will learn how the Bitbucket REST API takes care of administrative tasks for you.

Read on and start enhancing your GIT DevOps productivity!

## Prerequisites

This tutorial comprises hands-demonstrations. To follow, ensure you have the following:

*   A [Bitbucket](https://bitbucket.org/) account.

Related:[Learn this BitBucket Tutorial and Discover a GitHub Alternative](https://adamtheautomator.com/bitbucket-tutorial/)

*   [Postman](https://www.postman.com/) desktop application installed. This guide used Postman v10.5.6.

Related:[Go Behind The Scenes with a Postman Install and How-To Guide](https://adamtheautomator.com/postman-install/)

*   [Git](https://git-scm.com/) installed. This guide uses [Git](https://adamtheautomator.com/git-bash/) version 2.36.1.

Related:[How to Get Started with Git Bash on Windows](https://adamtheautomator.com/git-bash/)

## Authenticating Bitbucket with an App Password

Since REST APIs are available all over the internet, anyone can make a call to modify sensitive information. How do you mitigate this risk? An authentication check lets you determine the access level, allowing only administrators to install and evaluate apps.

Bitbucket Rest API provides various methods for authentication, including OAuth 2.0 Authentication and App passwords. But for a start, you will create an App password to authenticate Bitbucket.

To create an App password, follow these steps:

1\. Open your favorite web browser, and log in to [Bitbucket](https://bitbucket.org/dashboard/overview).

2\. Once logged in, click on your account profile (top-right), and select **Personal settings**. Your browser redirects to your **Personal settings** page (step three).

![Accessing the Personal settings page](https://adamtheautomator.com/wp-content/uploads/2022/12/image-241.png)

Accessing the Personal settings page

3\. Next, click **App passwords** (left panel) to access the App passwords manager page, and click **Create app password** to initiate creating an App password.

> 💡 _App passwords are tied to an individual account’s credentials. These passwords are useful to administrators to oversee Bitbucket-connected app testing while in development._

![Initiating creating an App password](https://adamtheautomator.com/wp-content/uploads/2022/12/image-242.png)

Initiating creating an App password

4\. Now, configure the App password with the following:

*   Provide a **Label** (i.e., **demoApp**), which serves as the name of the App password.Enable different types of [**Permissions**](https://support.atlassian.com/bitbucket-cloud/docs/app-password-permissions/) depending on your project requirements.Click on the **Create** button to finalize creating your App password.

![Specify the access level for the user of the App password](https://adamtheautomator.com/wp-content/uploads/2022/12/image-243.png)

Specify the access level for the user of the App password

5\. Lastly, copy the generated password from the **New app password** pop-up window, and save it somewhere safe for later use.

![Saving the new App password to authenticate the API calls in future](https://adamtheautomator.com/wp-content/uploads/2022/12/image-244.png)

Saving the new App password to authenticate the API calls in future

## Authenticating Bitbucket via OAuth 2.0

OAuth 2.0 is considered a more secure method to authenticate when you are uncomfortable using an App password. OAuth protocol for Bitbucket uses third-party OAuth/OIDC providers to authenticate API calls.

With OAuth 2.0, the provider issues an access token, which serves as proof of identity for an API call. As a result, you do not have to share password data as this behavior restricts the access level, and the token needs to be revoked after some time.

To set up OAuth 2.0, you will create a consumer who will be responsible for making API calls:

1\. On Bitbucket, click your profile (top-right), and select your workspace.

![Choosing a workspace](https://adamtheautomator.com/wp-content/uploads/2022/12/image-245.png)

Choosing a workspace

2\. Next, click **Settings** (left panel) on your workspace page to access your **workspace Settings**.

![Accessing the workspace settings](https://adamtheautomator.com/wp-content/uploads/2022/12/image-246.png)

Accessing the workspace settings

3\. Navigate to **OAuth consumers** under the **Apps and features** section, and click **Add consumer** to initiate adding a new consumer. Your browser redirects to a page where you can fill in consumer information (step four).

![Initiating adding a new consumer](https://adamtheautomator.com/wp-content/uploads/2022/12/image-247.png)

Initiating adding a new consumer

4\. Now, configure the new OAuth consumer as follows:

![Configuring the new OAuth consumer](https://adamtheautomator.com/wp-content/uploads/2022/12/image-248.png)

Configuring the new OAuth consumer

5\. Choose which **Permissions** to provide, similar to creating an App password, and click **Save** to finalize creating the new OAuth consumer.

Once created, your browser redirects to the OAuth consumers page (step six).

![Providing necessary permissions and creating the new OAuth consumer](https://adamtheautomator.com/wp-content/uploads/2022/12/image-249.png)

Providing necessary permissions and creating the new OAuth consumer

6\. Next, click on the consumer’s name to expand its information.

Note the generated **Key** and **Secret** value for the consumer, as you will need them to interact with the Bitbucket API.

![Confidential key and secret values](https://adamtheautomator.com/wp-content/uploads/2022/12/image-250.png)

Confidential key and secret values

Finally, open your terminal, and run the below `curl` command to acquire an access token using your key and secret values to interact with Bitbucket API. The request is made to the Bitbucket API endpoint reserved for generating an access token.

Ensure you replace `client_id` and `secret` with your OAuth consumer’s key and secret value, respectively.

```powershell

curl -X POST -u "client_id:secret" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials
```

Take note of the **access\_token**, as shown below. You can use this access token to send requests to the projects/repositories associated with your consumer workspace.

![Access token to authenticate API calls](https://adamtheautomator.com/wp-content/uploads/2022/12/image-251.png)

Access token to authenticate API calls

Related:[Essential CURL API Commands for Testing & Troubleshooting](https://adamtheautomator.com/curl-api/)

## Creating a Git Repository to Interact with Bitbucket API

Since you now have an access token, you are ready to interact with the Bitbucket API. How? You will create a repository as virtual project storage to save versions of your code.

A Git repository lets you track and manage the history of all changes made to repositories that belong to a specific workspace.

Retrieve your workspace ID first, which can be seen on the **Workspace settings** page.

![Workspace ID for a workspace](https://adamtheautomator.com/wp-content/uploads/2022/12/image-252.png)

Workspace ID for a workspace

Now, run the below command to create a repository, but ensure you replace the following:

*   `XXXX` – An identifier for your project within the workspace.
*   `{access_token}` – The access token you noted in the last step of the “Authenticating OAuth 2.0” section.
*   `{workspace_id}` – The ID of the workspace where you wish to create the new repository.
*   `{repo_name}` – A name to set for your repository.

```powershell
curl -X POST -H "Content-Type: application/json"-H "Authorization:Bearer {access_token}" -d '{
          "scm": "git",
           "project": {
                "key": "XXXX"
                }
     }' https://api.bitbucket.org/2.0/repositories/{workspace_id}/{repo_name}
```

> 💡 Bitbucket rest API supports the following endpoint for repositories. `POST /2.0/repositories/{*workspace_id*}/{repo_name}`

![Calling Bitbucket API to create a repository](https://adamtheautomator.com/wp-content/uploads/2022/12/image-253.png)

Calling Bitbucket API to create a repository

Related:[CURL Linux Command : Learning By Example](https://adamtheautomator.com/curl-linux/)

## Creating a User Group and Adding Users

For companies with many projects and employees, appropriate user access can be managed by creating user groups. All users belonging to a particular group share the same access privileges.

The 2.0 REST API version relies on 1.0 API resources for users and group management, as endpoints for 2.0 are not available yet.

> 💡 _Bitbucket Cloud REST API version 1.0 is deprecated, but Bitbucket supports the `/1.0/groups` endpoint to manage groups. The current working version is 2.0, but 1.0 still supports limited 1.0 API resources, which include group and invitation endpoints._

Run the following `curl` command to create a new group via API call.

The `groups` endpoint is useful for querying information about Bitbucket user groups, creating new ones, updating memberships, and deleting them. The caller needs to authenticate with administrative rights on an account to access its groups.

Ensure you replace the following accordingly, in each command, throughout this tutorial:

| Placeholder | Value |
| --- | --- |
| username:password | Your key and secret values if you are using OAuth2. But if you are using an App password, provide your username and the password you obtained from App password creation |
| {workspace\_id} | Your workspace ID. |
| group\_name or group\_slug | Your group’s name. |

```powershell
curl --request POST --user username:password https://api.bitbucket.org/1.0/groups/{workspace_id} --data "name=group_name"
```

![Create a new user group](https://adamtheautomator.com/wp-content/uploads/2022/12/image-254.png)

Create a new user group

Now, run the below command to add members to the newly-created group.

Replace `{group_slug}` with the group’s name and `{username}` with either the member’s unique account name or email. Members will receive an email notification of the invitation.

```powershell
curl --request PUT --user username:password --header "Content-Type: application/json" https://api.bitbucket.org/1.0/groups/{workspace_id}/{group_slug}/members/{username}/ --data '{}'
```

If executed successfully, the response body contains details about the newly added user, including user display name and User ID (UUID), as shown below.

![Adding a user to an existing group](https://adamtheautomator.com/wp-content/uploads/2022/12/image-255.png)

Adding a user to an existing group

Below, you can see a member is successfully added to the group (**dev\_group**) in Bitbucket and now has access to all the repositories in the assigned workspace.

![Verifying a user is successfully added to a group](https://adamtheautomator.com/wp-content/uploads/2022/12/image-256.png)

Verifying a user is successfully added to a group

## Listing All Pull Requests

Since Git is a version control system (VCS), your repository will have different versions of changes. How do you put these versions together? You need a pull request to merge the local repository changes to the main or developer branch.

Mind you, though, that pull requests must be approved by an administrative user after proper review. So, you first need to get a list of all the pull requests using Postman, an API testing application that presents the API response in a readable form.

Launch Postman, choose the **GET** option from the dropdown field, and run the below URL to list all pull requests for a specified repository.

```
https://api.bitbucket.org/2.0/repositories/{workspace_id}/{repo_name}/pullrequests
```

Below, you can see that Postman is like cURL’s GUI version. cURL offers a command line utility to transfer data over URLs. Postman does the same job but provides an interactive UI.

Take note of the commit ID in the **hash**, as shown below, which you (an admin) will use to approve the pull request.

![Listing all pull requests with other complete details of the contributor](https://adamtheautomator.com/wp-content/uploads/2022/12/image-257.png)

Listing all pull requests with other complete details of the contributor

But if you prefer cURL, run the below `curl` command instead to list all the pull requests for a specified repository. But from this point throughout the tutorial, ensure you replace `{workspace_id}`, `{repo_name}`, and `{access_token}` in each endpoint URL and command.

```powershell
curl --request GET --url 'https://api.bitbucket.org/2.0/repositories/{workspace_id}/{repo_name}/pullrequests' --header 'Authorization: Bearer {access_token}' --header 'Accept: application/json'
```

## Reviewing and Responding to Commits (Approve/Unapprove)

A commit is an action that sends the latest source code to the repository using a pull request. But a pull request will just be lying around without an admin’s commit approval.

The updated code needs to be revised before it is merged into the main repository. As an admin user with access privileges, you can approve or reject specified commits using Bitbucket API.

Choose the **POST** option from the dropdown field in Postman, and run the following URL to approve a commit. Ensure you replace `{commit_ID}` with the commit ID you noted in the last step of the “Listing All Pull Requests” section.

```
https://api.bitbucket.org/2.0/repositories/{workspace_id}/{repo_name}/commit/{commit_ID}/approve
```

You can see below that the commit has the approved status (**”approved”: true** or **200 OK**).

![Approving a specified commit](https://adamtheautomator.com/wp-content/uploads/2022/12/image-258.png)

Approving a specified commit

For cURL, run the below command to approve a specific commit, replacing `{commit_ID}` with the commit ID you plan to approve.

```powershell
curl --request POST --url 'https://api.bitbucket.org/2.0/repositories/{workspace_id}/{repo_name}/commit/{commit_ID}/approve' --header 'Authorization: Bearer {access_token}' --header 'Accept: application/json'
```

> 💡 _Similarly, users with explicit access to the repository can Redact specified commits using the following command._

```powershell
curl --request DELETE --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_name}/commit/{commit}/approve' --header 'Authorization: Bearer {access_token}
```

## Deleting Groups and Repositories

Cleaning your workspace is one way of enhancing productivity. Who would not want a clutter-free environment? But how? Delete groups and repositories that do not serve any purpose.

So long as you are the root user with admin rights to delete a group of users, cleaning your workspace is just a few steps away.

Switch to the **DELETE** option, and run the following URL to delete a specific group

```
https://api.bitbucket.org/1.0/groups/{workspace_id}/{group_slug}
```

You can see below that the status is **204 No Content**, which indicates the group no longer exists.

![Verifying the delete request is successfully processed](https://adamtheautomator.com/wp-content/uploads/2022/12/image-259.png)

Verifying the delete request is successfully processed

For cURL, run the below command to delete a specific group.

```bash
curl --request DELETE --user username:password --header "Content-Type: application/json" https://api.bitbucket.org/1.0/groups/{workspace_id}/{group_slug}/
```

Now, run the below URL to delete a specific repository.

```
https://api.bitbucket.org/2.0/repositories/{workspace_id}/{repo_name}
```

Below, you can see the same **204 No Content** status, which tells you the repository no longer exists.

![Verifying a repository has been deleted from the Bitbucket cloud](https://adamtheautomator.com/wp-content/uploads/2022/12/image-260.png)

Verifying a repository has been deleted from the Bitbucket cloud

But for cURL, run the following command to delete a repository permanently.

```powershell
curl --request DELETE --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}' --header 'Authorization: Bearer {access_token}'
```

## Conclusion

This tutorial has walked you through all the necessary practices carried out by a Bitbucket administrator user. Specifically, you have learned to create, manage and control access to Bitbucket workspaces using Bitbucket API calls.

APIs are the fastest and easiest ways to manage various Bitbucket operations without going through the manual setup. Bitbucket uses standard HTTP requests to access and use data, making it compatible with any programming language or framework.

The API is of great help to streamline [workflows](https://confluence.atlassian.com/bitbucketserver076/workflow-strategies-in-bitbucket-server-1026534864.html) and maintain high-quality code. Why not move ahead with setting up [Bitbucket Pipelines](https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines/)? Bring continuous delivery by synchronizing Bitbucket API events!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fbitbucket-api%2F&text=Bitbucket%20API%3A%20Boost%20Your%20GIT%20DevOps%20Productivity)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fbitbucket-api%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fbitbucket-api%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/04/Learn-this-BitBucket-Tutorial-and-Discover-a-GitHub-Alternative.jpg)

### [BitBucket Tutorial: Your Guide to a Powerful GitHub Alternative](/bitbucket-tutorial/)

Need a project tool with seamless team workflow? This Bitbucket tutorial will expand your DevOps horizon as it shows you how it simplifies DevOps collaboration.

![](https://adamtheautomator.com/wp-content/uploads/2021/08/How-to-Get-Started-with-Git-Bash-on-Windows.jpg)

### [Getting Started with Git Bash Commands on Windows](/git-bash-commands/)

Start your journey with Git and learn about Git Bash commands on Windows and run some basic commands on Git Bash terminal on Windows in this tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2020/12/Wrangling-REST-APIs-and-JSON-with-PowerShell.jpg)

### [PowerShell and JSON: A Comprehensive Guide](/powershell-json/)

Learn how to use PowerShell and JSON together, including converting and parsing JSON, with real-world examples.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
