It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Trying to create new repo using API v2 and curl via shell script

Hello. I am trying to create a new, empty, private repository in my bitbucket.org account via the command line (shell, whatever) using `curl`.

I think there are certain steps that I need to take but I don't understand what they are, that is to say, I think I'm missing something, despite trying to Google my way out of this.

So I'm going to show what I've tried, and see if maybe someone who knows more than I do can point out what I am doing wrong.

n.b - My BitBucket account has 2-Step/2-Factor turned on, so I created an “App password” with the ability to read/write/admin repositories.

I've replaced my app password with 'XXXXXXXXXXXXXXXX' but otherwise everything is exactly how I entered it

curl -i -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {XXXXXXXXXXXXXXXX}" \
-d '{
"scm": "git",
"is_private": true,
}' "https://api.bitbucket.org/2.0/repositories/{tjluoma}/{new-test-repo}"

 

Result: I get this message back:

 

{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}

I'm not sure what an access token or a refresh token is, exactly, but I've tried various things, and none of them have worked:

curl -X POST -u "tjluoma: XXXXXXXXXXXXXXXX" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials

Result:

{"error_description": "Invalid OAuth client credentials", "error": "unauthorized_client"}

So how do I authorize… curl?

Next I tried this:

 

curl -S --location --fail -u "tjluoma: XXXXXXXXXXXXXXXX" "https://bitbucket.org/site/oauth2/authorize?client_id={tjluoma}&response_type=code"

but that just gave me this:

Result: curl: (22) The requested URL returned error: 401 

 

So I'm rather stuck and feeling stupid. If anyone would be willing to offer some advice, I'd be most appreciative. Thanks for your time

 

1 answer

1 accepted

0 votes
Answer accepted

Note: I finally figured it out. I was trying to use OAuth when I didn't need to be, because I had created an app password.

You can see my working script at https://bitbucket.org/tjluoma/new-dual-repo/src

Is there no other way to do it? 

Suggest an answer

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

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

4,033 views 4 22
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