Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Delete/Remove user from bitbucket cloud using Bitbucket API

Mayank January 18, 2023

I intend to delete users from the Bitbucket cloud programmatically using the bitbucket api
but can't seem to find the right endpoint,please help me find or provide the right api
also i would like to delete by passing email associated with the account is there a way to do that?

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 19, 2023

Hello @Mayank ,

Currently, you can only remove a user from your bitbucket workspace using the public API endpoint below : 

We have an open feature request to implement the ability to delete users from the workspace, both from the user groups and direct access. You can access the feature using the following link : 

I would suggest you to add your vote there, since this helps both developers and product managers to understand the interest. Also, make sure you add yourself as a watcher in case you want to receive first-hand updates from that ticket. Please note that all features are implemented with this policy in mind.

As a workaround, you can also use the below Python script to remove user access.

 The above script was produced by an individual within our support team and is not directly supported by Atlassian or our Support team as a whole. This is provided on a best efforts basis and is provided AS IS to try to assist you as much as possible. We recommend you have your dev team review it and ensure you understand what it is attempting to accomplish before executing it. If you would like to change or add functionality to the script, feel free to do so at your end.

Thank you, @Mayank .

Patrik S

Mayank January 19, 2023

Thankyou,i have one more query , currently using App password to authenticate api access using token but it is not authenticating and sends 404 error on each request i make.
Below is the sample code

# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
import json

url = "https://api.bitbucket.org/2.0/user/permissions/repositories"

headers = {
"Accept": "application/json",
"Authorization": "Bearer <access token>"
}

response = requests.request(
"GET",
url,
headers=headers
)

print(response)
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 25, 2023

Hello @Mayank ,

From the snippet you shared, it seems like your code is currently configured to use Bearer tokens in the Authorization header, which requires you to use OAuth 2.0 and get an access token. 

The other type of authentication is called Basic Auth, which uses your bitbucket username and an app password as the credentials for the Authentication head. To use basic auth you will need to configure the headers to be like the below : 

"Authorization": "Basic <encoded credentials>"

Where the <encoded credentials> placeholder needs to be replaced by the base 64 encoded of your bitbucket username and app password separated by a colon.

For example : 

mybbusername:myapppassword

base 64 encoding would generate

bXliYnVzZXJuYW1lOm15YXBwcGFzc3dvcmQ=

And the resulting Authorization header would be

"Authorization": "Basic bXliYnVzZXJuYW1lOm15YXBwcGFzc3dvcmQ="

Hope that helps! Let me know in case you have any questions.

Thank you, @Mayank !

Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events