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

How do i create a bitbucket repo using REST API in our company bitbucket

Srini
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 10, 2018

We have a company wide bitbucket and I have an account and have an existing project.  Could someone please help me how to create a repo using REST API call. I can access bitbucket using  the "bitbucket.<company_name>.com" and create a repo manually.

Thanks in advance for the help.

2 answers

3 votes
Alexey Matveev
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.
November 10, 2018
Srini
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 11, 2018

Hi Alex, thank you so much for your help, I think I'm in  the right direction now, I followed the link that you mentioned above and created my json and ran the curl command as mentioned below for creating a repo in a project, i got the response as :
           "Repository abc/test does not exist."

and when i created the same repo manually and run the same below command it says:          
           "This repository URL is already taken by 'test'  in 'ABC'".

and when i don't mention reponame in the url ( just https://bitbucket.<mycompany>.com/rest/api/1.0/projects/abc/repos" and it says:
        

             "A repository name must be provided to create a repository."

Here is my command: 

curl -u <username>:<password>  -X POST -H "Content-Type: application/json" -d '{

   "slug": "test",

   "forkable": false,

   "project": {

        "key": "ABC"

    }

}' https://bitbucket.<mycompany>.com/rest/api/1.0/projects/abc/repos/test

In the above command, 'abc' is my project, 'ABC' is my project key and 'test' is the repo that I'm trying to create.

Could you please check if I'm doing anything wrong? Thank you so much for your help.

 

Like # people like this
Neel Devani
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 28, 2022

Hey @Alexey Matveev 

Do you know to create a new repo from existing repo but of a specific branch only currently if I apply @Srini 's solution the new repo, I create has all the branch from the parent repo, do you what else we need to add in the body of request so that the new forked repo consist only the branch that I want to create from parent repo

I couldn't find that in docs.

I tried giving the id of the branch in the Json body but didn't work.

Best Regards,
Neel.

1 vote
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 20, 2018

Hey Srini,

From the create repo endpoint, it looks like the wrong URL might be called in your curl command. The endpoint you'll want to hit is:

https://bitbucket.yourcompany.com/rest/api/1.0/projects/ABC/repos

(swapping out yourcompany and ABC with the correct values)

The slug doesn't need to contain the project - just the repo name and scmId:

{
    "name": "My repo",
    "scmId": "git",
    "forkable": true
}

Hope that helps!

Cheers,
Daniel 

Sid January 24, 2019

Hi@Eaniel Deads, can we create multiple repos at the same time using the above method?

 

Thanks

Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 11, 2019

Hi Bney,

The endpoint only accepts one project at a time. If you need to create multiple projects, I'd suggest using a loop in your code to iterate over the list of projects you need to create and submit a new API request for each one.

Cheers,
Daniel

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events