Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitbucket API 2 - create repository in a team project

I have a team on my bitbucket account, myteam, which contains a project named mainproject. Whenever I want to create a repository inside I only need to execute this command line:

$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo1" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks"}'

This works. However the issue arises when I create a second project, named secondproject. How am I supposed to tell the API to which project the repository should belong?

I tried specifying the project information in the data (-d):

$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"name": "secondproject"} }'

or with the key parameter:

$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"key": "SEC"} }'

This will create the repository repo2 in the project mainproject.

I tried using the uuid but the same occurs, repo is created in the mainproject.

I tried putting the project name in the link:

$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/secondproject/repo1" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks"

...
{"error": {"message": "Resource not found", "detail": "There is no API hosted at this URL.\n\nFor information about our API's, please refer to the documentation at: https://confluence.atlassian.com/x/IYBGDQ"}}

How can I specify which project the repository I want to create belongs to? I am not looking for a GUI solution, I want to stick to the command line as I need to automatize the creation of repositories this way.

like image 872
kaligne Avatar asked Jul 13 '16 09:07

kaligne


1 Answers

The content type has to be specified to curl with this argument: -H "Content-Type: application/json". Then the json data would be accessed normally. So the final command would look like this:

$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -H "Content-Type: application/json"  -d '{"has_wiki": true, "is_private": true, "project": {"key": "PRJ_KEY"}}'
like image 174
kaligne Avatar answered Nov 02 '22 01:11

kaligne