Hello everyone,
I’m running into an issue with Bitbucket Cloud authentication that I haven’t been able to resolve even after following the official API token documentation.
I have an automation agent (Python) that uploads Terraform files into a Bitbucket Cloud repository using the REST API endpoint:
POST https://api.bitbucket.org/2.0/repositories/<workspace>/<repo>/src
This upload used to work in a previous Bitbucket workspace using a Bitbucket App Password with Basic Auth (username:app-password).
However, in a new workspace/repository, all authentication attempts now fail with HTTP 401 Unauthorized, even though the same code and same method still work elsewhere.
curl -u "myuser:my_app_password" https://api.bitbucket.org/2.0/user
Result → 401 Unauthorized
(Same command succeeds in my older workspace)
curl --user "myemail@company.com:my_token" \ https://api.bitbucket.org/2.0/repositories/<workspace>/<repo>/commits
Result → 401 Unauthorized
curl -H "Authorization: Bearer <token>" https://api.bitbucket.org/2.0/user
Result → 401 Unauthorized
Bitbucket App Password
Bitbucket API Token
Both behave the same.
Tokens were created with:
Repository: Read
Repository: Write
Account Read
Printing environment variables inside the agent shows correct username/token.
Despite this, every authentication attempt in this specific workspace returns 401.
Bitbucket responds with:
HTTP/2 401 www-authenticate: BitbucketCustom realm=Bitbucket.org HTTP
or for OAuth-style tokens:
"Token is invalid, expired, or not supported for this endpoint." Even though the token(s) were freshly regenerated.
Using the same credentials locally works for Git clone.
Using the same pattern of API call works for another workspace.
Only the REST API authentication fails in the new workspace.
Are App Passwords or API Tokens still supported for uploading files via:
POST /2.0/repositories/{workspace}/{repo}/src in all workspaces?
Is there a workspace/org setting that could silently block token-based REST authentication?
Is there a way to debug why Bitbucket rejects the token (e.g., audit logs, access logs)?
Is this known behavior when Atlassian Access or SSO is enabled?
If anyone has encountered App Password / API Token 401 failures only for REST API calls, especially with:
Workspace-level security
Atlassian Access
SSO restrictions
Specific repo permission models
Thanks in advance!