Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

tjluoma August 23, 2018

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

1 vote
Answer accepted
tjluoma August 24, 2018

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

neomatrix369 June 22, 2019

Is there no other way to do it? 

tjluoma July 24, 2019

I don't know if there are any other ways to do it… there may well be… but this is an easy way that worked the way that I was trying to get it to work. FWIW.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events