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


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" \ \
  -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.



3 answers

1 accepted

1 vote
Accepted answer

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"} }'

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

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

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.

Thanks for the update and giving a time frame.

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 ?


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) ??

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?


By adding "name" parameter to post data:

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

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

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:

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

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? 

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

Hello, I have tried the following command:

curl -X POST -v -u user:pass -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
* 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 left intact
{"error": {"message": "Forbidden"}}

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.

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 -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 ?

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

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?

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.

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.



curl -X POST -v -u user:pass -H "Content-Type: application/json" -d '{"is_private": true, "language": "php", "project": {"key": "PROJ"}}'


* upload completely sent off: 66 out of 66 bytes
* 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=" 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!

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?

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".

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{projectkey}/repos -H "Content-Type: application/json" -d "{\"name\": \"{reponame}\",\"scmId\": \"git\", \"forkable\": true }"\ worked for me for successful creation of Repository in project.



Hi Neetu,

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

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$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
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

679 views 5 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you