Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

zalman.goldstein
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 22, 2021

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
Atlassian Team members are employees working across the company in a wide variety of roles.
November 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
AUG Leaders

Atlassian Community Events