I am trying to create an app for my workspace usin atlassian-python-api package but can't call APIs.
Asked by Ishita Chauhan:

Hi everyone, I am new here. So it might be the case that I am missing something. It would be of great help if someone could guide me through the process. I wrote the following python code to try and get a list of all the users associated with my organization:

```
from atlassian import Bitbucket
import os

class Driver():
??? def __init__(self):
??? self.base_url='https://bitbucket.org'
??? self.username = "admin"
??? self.app_password = os.environ.get('BITBUCKET_APP_PASSWORD')

??? self.bitbucket = Bitbucket(
??? ?? url=self.base_url,
??? ?? username=self.username,
??? ?? password=self.app_password
??? )

??? def getVendorData(self):
??? ?? response = self.bitbucket.get_users()
??? ?? print(response.status_code)
??? ?? print(response)
```

I have created the ++BITBUCKET_APP_PASSWORD++ for an admin account and have granted it literally all the permissions. Bit when I try to run the \`getVendorData\` method I get:
> requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: <https://bitbucket.org/rest/api/1.0/use>  
> rs?limit=25  
>
Note: The app I am working on is still in a testing phase so I am using a free Bitbucket test workspace.

Thank you for your time


Answers:
author: Aron Gombas
body: I think that the problem is not with the permissions, but your code can't authenticated using the given username and password.

1. Are you 100% sure that "admin" should be used here? AFAI Bitbucket Cloud is using email addresses to identify user accounts...
2. Are you sure that the password is correctly set in the *local* environment variable? Maybe printing this out from the script could confirm this.


author: Patrik S
body: Hello [@Ishita Chauhan](/t5/user/viewprofilepage/user-id/5162176) ,

Welcome to Atlassian Community!

From the logs you have shared seems like this library is trying to use Bitbucket API v1.0 endpoints, which were deprecated a few years ago (see [Users endpoint 1.0](https://support.atlassian.com/bitbucket-cloud/docs/users-endpoint-10/)).

In this case, you would need to use the endpoints available in Bitbucket API v2.0. If your goal is to list all the members within a workspace, the following 2.0 endpoint might be of help :

* <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-members-get>

You can also check all the other available endpoints in the [Bitbucket API 2.0 Reference](https://developer.atlassian.com/cloud/bitbucket/rest/intro/) documentation.

Also, I see that in your script you are using the username "admin". The username used in the authentication must be the same username of the account under which you created the [app password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/). You can check the username of your account on the website by clicking on your personal avatar in the top right corner, selecting **Personal Settings** , and looking for the field **Username**. This should be the username used in your script.

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

Thank you, [@Ishita Chauhan](/t5/user/viewprofilepage/user-id/5162176) !

Patrik S


Tags: bitbucket-cloud

cloud