Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,849
Community Members
 
Community Events
165
Community Groups

Can't create repo in a bitbucket cloud with curl and access token

I am trying to create a repo in bitbucket cloud with:

curl --request GET \
  --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}' \
  --header 'Authorization: Bearer <access_token>' \
  --header 'Accept: application/json'

The problem is with the "access_token".
I tried to put there my app password, ssh key, login password, but I always get back the same error:
{"type": "error", "error": {"message": "Access token expired."}}

I created a 
OAuth 2.0 key and secret, but can't extract a access token from them:

curl -X POST -u "key:secret" \
  https://bitbucket.org/site/oauth2/access_token \
  -d grant_type=authorization_code -d code={code}

returns 
error: "Cannot use client_credentials with a consumer marked as \"public\". Calls for auto generated consumers should use urn:bitbucket:oauth2:jwt instead.", "error": "invalid_grant"}

1 answer

0 votes
Patrik S Atlassian Team Nov 26, 2021
Hello Zalman,

Welcome to Atlassian Community!
I understand you’re trying to create a repository using Bitbucket API, so I would like to highlight a few points on why you are getting these errors :
  • HTTP Method : From the request you shared with us you’re using the GET method, which is used return an object describing a given repository. In order to create a new repository you should use the POST method instead.
  • Authentication Method: I’ve noticed you’re trying to use OAuth2 flow to authenticate your request, and this is usually used to integrate with other applications. In your case I would suggest using the Basic Authentication flow, providing your username and App Password.

That being said, in order to create a new repository using Basic Authentication your cUrl command would look like the following :

curl -u "<Bitbucket Username>:<AppPasswords>" -X POST -H "Content-Type: application/json" -d '{
"scm": "git",
"is_private": true,
"project": {
"key": "<your project key>"
}
}' https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>
If the project is not provided, the repository is automatically assigned to the oldest project in the workspace.
Please note that App Passwords are different from account passwords. If you haven’t created an AppPasswords yet, you can do so following these steps
Also, you can reference to the following documents for more details about the API call and authentication methods :

 

Hope that helps to address your questions, let me know if this works for you!

Thanks, Zalman!
Kinds regards,
Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,247 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you