- If you are using Bitbucket Cloud(bitbucket.org) You can use the Bitbucket REST API and cURL and also to specify the Project key for the repository you can use this:-
curl -X POST -v -u $username:$password "https://api.bitbucket.org/2.0/repositories/$username/$reponame" -H "Content-Type: application/json" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"key": "'$project_key'"}}'
This will create a repository under a specific Project.
- If you want to create a repository in Bitbucket server V1.0 REST API is available for that. The command would look like this:-
curl -u $username:$password -X POST -H "Content-Type:application/json" -d '{"name": "'$reponame'","scmId": "git","forkable": true}' http://localhost:7990/rest/api/1.0/projects/${project_key,,}/repos
You can mention your company url(exmple - birbucket.xyz.com) in place of localhost:7990.
See Use the Bitbucket Server REST APIs for more information on bitbucket server.