How do you create a project or project repository on bitbucket cloud using REST ?

Mickaël PERRIN April 21, 2016

Hi,

I manage to successfully create a repository using the REST API by using that kind of REST call:

curl -X POST -v -u username:password -H "Content-Type: application/json" \
  https://api.bitbucket.org/2.0/repositories/teamsinspace/new-repository4 \
  -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }'

However, this repository is created in an arbitrary project ? How can I specify the project when creating the repository ?

I didn't find anything related to project management in the REST documentation.

Thanks

 

5 answers

1 accepted

2 votes
Answer accepted
evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2016

Project support in some of our APIs (like repo creation) is lagging a bit. You are not currently able to a specify which project a repo should be created into. Know that we are actively working on filling those gaps though.

Once finished, you'll be able specify the project by adding the project object to your repo payload in the same way as it is currently included in the repo object:

 

-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"key": "MYPROJ"} }'
Mickaël PERRIN April 21, 2016

Thanks, even if it's not the answer I expect to hear sad

Mickaël PERRIN April 27, 2016

@Erik van Zijst Are there any improments over this in the professionnal/private/paid version of Bitbucket ?

abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2016

I'm the engineer currently working on the projects API and integrating projects into the rest of the APIs. As far as I can see, the work should be finished in 3 weeks, assuming no unexpected work derails the timeline (famous last words). Sorry for the inconvenience.

Mickaël PERRIN April 27, 2016

Thanks for the update and giving a time frame.

Mickaël PERRIN June 9, 2016

Hey @Abhin Chhabra and @Erik van Zijst,

do you have any updates on this ? I saw there was some announcements on bitbucket, but didn't see if there was improvements over the REST API ?

Thanks

santosh verma May 15, 2017

Sorry to jump in this conversation ...

I'd like to craete bew repo in bitbucket by using REST version 1, seems my bitbucket server does not support version 2.

So can some help me out to know correct syntex to create repo in specific project (for version 1) ??

Daniel Ferreira Castro March 16, 2018

Hi, do you have updates about this issue?  Are we able at this moment to create a repository inside an specific project using API?  If yes, how should we invoke the api?

1 vote
J.Fawkes April 21, 2016
Hi,

By adding "name" parameter to post data:

-d '{"scm": "git","is_private": "true","fork_policy":"no_public_forks","name":"NewRepo"}' 

https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html#repositoryResource-POSTanewrepository

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2016

The OP is asking how to specify the project, not the name.

0 votes
Carthik Annayan July 8, 2019

Hi Guys, 

Can anyone answer this question please? I'm trying to create a "Project" via API/bash script and the bit bucket  API documentation is terrible. Any direction pointing to the correct API is much appreciated. I'm using bitbucket version 5.10.1

 

Cheers, 

Carthik

0 votes
Rashmi April 30, 2019

Hi,

 

Can someone please confirm the curl command to create new Bitbucket project as well as repo?

My bbt repo is something like below:

 

https://abc-bbt.corp.abc.com/bitbucket
0 votes
abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2016

Hey. The basic project API has now been deployed. So you can created/update/delete projects via the API. You can see the documentation for that here: https://developer.atlassian.com/bitbucket/api/2/reference/search?q=tag:projects

Support for choosing the project during repository creation was recently finished and is in our deployment pipeline. It should get deployed today.

Roger Gullhaug August 2, 2016

Hi, I have tried to specify project during repository creation like this:

{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"key": "MYPROJ"} }

but can not get it to work. Am I not doing it correct? 

abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 2, 2016

Could you please paste the exact command you're using and the actual response you're getting?

batanero August 3, 2016

Hello, I have tried the following command:

curl -X POST -v -u user:pass https://api.bitbucket.org/2.0/repositories/myteam/myrepo -H "Content-Type: application/json" -d '{"is_private": true, "language": "php", "project": {"key": "PROJ"}}'

and got the response:

* upload completely sent off: 67 out of 67 bytes
< HTTP/1.1 403 FORBIDDEN
* Server nginx/1.6.2 is not blacklisted
< Server: nginx/1.6.2
< Vary: Authorization, Cookie
< Content-Type: application/json; charset=utf-8
< Strict-Transport-Security: max-age=31536000
< Date: Wed, 03 Aug 2016 19:56:55 GMT
< X-Served-By: app-111
< X-Static-Version: c4b639339c4d
< ETag: "2517d8a35dee8cb8cd9e5f0c889915ba"
< X-Render-Time: 0.0306060314178
< X-Accepted-OAuth-Scopes: repository:admin
< Connection: keep-alive
< X-Version: c4b639339c4d
< X-Request-Count: 235
< X-Frame-Options: SAMEORIGIN
< Content-Length: 35
< 
* Connection #0 to host api.bitbucket.org left intact
{"error": {"message": "Forbidden"}}
abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2016

Hi Luiz,

That exact payload works fine for me. So perhaps the problem is auth related. Perhaps you don't have access to create repositories on that account. Or perhaps if you're using something that allows scopes (app passwords, for example) and don't have the "repository:admin" scope.

Please let me know if any of those 2 guesses help you.

Neetu August 3, 2016

Hi Abhin, sorry to jump in, but creating repo for specific Project is not working for me either.

I am using 

curl -X POST -v -u abc:abc http://abc.test.com/2.0/repositories/projectname/repositoryname -H "Content-Type: application/json" -d '{"is_private": true, "language": "php", "project": {"key": "projectkey"}}'

I get this

* upload completely sent off: 69 out of 69 bytes
< HTTP/1.1 404 Not Found
< Server: Apache-Coyote/1.1
< X-AREQUESTID: @<redacted>
< X-ASEN: SEN-5840674
< X-AUSERID: 4064
< X-AUSERNAME: <redacted>
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Set-Cookie: JSESSIONID=<redacted>; Path=/; HttpOnly
< Pragma: no-cache
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Cache-Control: no-cache
< Cache-Control: no-store
< Content-Type: text/html;charset=UTF-8
< Content-Language: en-US
< Transfer-Encoding: chunked
< Vary: Accept-Encoding

What am i doing wrong here ?

Neetu August 3, 2016

That User has sys admin permissions. So access is not an issue for me

abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2016

Neetu: I think your URL might be wrong. I see that you're using "projectname" after "repositories". The account/team username is supposed to go there.

Luiz: I think I might know what's going on. This might be an actual bug with BB, where it requires one to be an account admin for creating repos using the API. I fear that the authorization requirements of creating a repo via the API vs. the UI have gone out of sync. I have a bugfix PR out and it should get merged and deployed in a couple of days. The bug would be my fault and I apologize for that. In the mean time, could you please try to authenticate as an account admin?

batanero August 3, 2016

Thanks for the reply Abhin. I think this is it, the authorization requests are different via API vs UI. However, even authenticating as an admin I can only create repositories under the default PROJ project, when I try to create one on a different one I get an unathorized response. Can you look into that too? Thank you.

abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2016

Hi Luiz,

That's a bit strange. I am able to create repositories under various projects just fine. Could you please paste the curl command you used for creating a repo in another project and the actual result you got? Thanks.

batanero August 4, 2016
Command:

 

curl -X POST -v -u user:pass https://api.bitbucket.org/2.0/repositories/myteam/myrepo -H "Content-Type: application/json" -d '{"is_private": true, "language": "php", "project": {"key": "PROJ"}}'

 

Response:
* upload completely sent off: 66 out of 66 bytes
&lt; HTTP/1.1 401 UNAUTHORIZED
* Server nginx/1.6.2 is not blacklisted
&lt; Server: nginx/1.6.2
&lt; Vary: Cookie
* Authentication problem. Ignoring this.
&lt; WWW-Authenticate: Basic realm="Bitbucket.org HTTP"
&lt; Content-Type: text/html; charset=utf-8
&lt; Strict-Transport-Security: max-age=31536000
&lt; Date: Wed, 03 Aug 2016 21:14:16 GMT
&lt; X-Served-By: app-112
&lt; X-Static-Version: c4b639339c4d
&lt; ETag: "d41d8cd98f00b204e9800998ecf8427e"
&lt; X-Render-Time: 0.016921043396
&lt; Connection: keep-alive
&lt; X-Version: c4b639339c4d
&lt; X-Request-Count: 111
&lt; X-Frame-Options: SAMEORIGIN
&lt; Content-Length: 0
Thanks for the help!
abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2016

Hi Luiz,

Unfortunately, I'm not able to reproduce this issue locally. Can you tell me some details about the team and the project? For example, is the project public or private. I also know that you're attempting this as an admin on the team.

Also, I noticed that this is an authentication problem and not an authorization problem. Can you confirm that you are attempting this with the same set of credentials as were used to create the repo in the PROJ project?

abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2016

I also understand that you feel uncomfortable sharing all the details of your request on a public forum (as you should). Feel free to contact me via email using "abhin at atlassian.com".

Neetu August 4, 2016

Thanks Abhin for the quick reply. I was not able to create it the way you suggested.I think 2.0 is for Bitbucket cloud ? We are using bitubucket server4.4

 

curl -X POST -v -u user:pass http://abc.com/rest/api/1.0/projects/{projectkey}/repos -H "Content-Type: application/json" -d "{\"name\": \"{reponame}\",\"scmId\": \"git\", \"forkable\": true }"\ worked for me for successful creation of Repository in project.

 

Thanks

abhin-atl
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2016

Hi Neetu,

Yes, this is all for Bitbucket Cloud. The question is also tagged as "bitbucket-cloud". Bitbucket server has a different API.

Dave Young October 30, 2017

Hi Abhin,

I'm also having a hard time getting this to work. This is the code I'm using:

curl -X POST -v -u $BB_UN:$BB_PW https://api.bitbucket.org/2.0/repositories/digitaldeployment/$SITE_NAME -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"key": "Tools"} }'

I'm able to create a repo, but it doesn't go to the appropriate project.

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events