# Bitbucket Cloud Configuration

## Creating an API Token in Bitbucket Cloud

**Supported Bitbucket Cloud Authentication**  
For secure authentication with Bitbucket Cloud, use API tokens with scopes. API tokens are the supported authentication method for this integration. For more information, refer to the official [Bitbucket Cloud documentation on API tokens](https://support.atlassian.com/bitbucket-cloud/docs/api-tokens/).

When configuring this integration, use the user's Atlassian email as the username and the API token as the password. [Create the token](https://help.sonatype.com/en/bitbucket-cloud-configuration.html#create-an-api-token "Create an API Token") with the required Bitbucket Cloud scopes to allow the integration to access repositories, pull requests, workspace information, and user information.

### Required API Token Scopes

- Read  
  `read:pullrequest:bitbucket`  
  `read:repository:bitbucket`  
  `read:user:bitbucket`  
  `read:workspace:bitbucket`

- Write  
  `write:pullrequest:bitbucket`  
  `write:repository:bitbucket`

### Create an API Token

Follow the steps listed below to create an API token with scopes for automated pull requests and automated commit feedback:

1. Log into Bitbucket Cloud.
2. Select your profile avatar and open _Account settings_.
3. In the account settings menu, open _Security_.
4. In the _API tokens_ section, select _Create and manage API tokens_.
5. Click _Create API token with scopes_.
6. Enter a label for the token and select an expiration date according to your organization's requirements.
7. Select _Bitbucket_ as the product, then add [the required scopes](https://help.sonatype.com/en/bitbucket-cloud-configuration.html#required-api-token-scopes "Required API Token Scopes").
8. Click _Create_, then copy and save the API token somewhere safe.

After the token is created, when configuring the [Source Control in IQ Server](https://help.sonatype.com/en/source-control-configuration.html "Source Control Configuration"), enter your Bitbucket Cloud login email address as the username and the API token as the password.

See [this article for more information on Bitbucket Cloud API tokens](https://support.atlassian.com/bitbucket-cloud/docs/api-tokens/).

## Protecting the Target Branch

You can prevent users from merging Pull Requests with failing IQ Policy Evaluations two ways in Bitbucket Cloud. IQ Policy Evaluations must be set to Fail at the Source Stage.

1. For all accounts, users get notified when they don't have that number of successful builds for the most recent commit.
2. For premium accounts, users won't be able to merge if their pull request has unresolved merge checks.

Click _Repository Settings_  _Workflow_  _Branch restrictions_.

|     |
| --- |
|  |

Select the a branch option and desired write and merge access. Select _Minimum number of successful builds for the last commit with no failed builds and no in progress builds_ in the _Merge checks_ section under the _Merge settings_ tab.

This will inform users that the requirements are not fulfilled when trying to merge. **It will not prevent the merge.**

Premium accounts have the additional ability to prevent the merge.

This will prevent users from merging a pull request with a failed build.

|     |
| --- |
|  |

See these pages for more information:

- [https://support.atlassian.com/bitbucket-cloud/docs/suggest-or-require-checks-before-a-merge/](https://support.atlassian.com/bitbucket-cloud/docs/suggest-or-require-checks-before-a-merge/)
- [https://support.atlassian.com/bitbucket-cloud/docs/use-branch-permissions/](https://support.atlassian.com/bitbucket-cloud/docs/use-branch-permissions/)
