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

Create and configure a Bitbucket Server repository using the REST API endpoints

How to create a repository using the REST API endpoints?

To create a new repository, we will be using the following endpoint:

POST /rest/api/1.0/projects/{projectKey}/repos

 

When using curl, the full command looks like this:

curl --user <user>:<password> -H "Content-Type: application/json" --data @input.json -X POST <Bitbucket URL>/rest/api/1.0/projects/<projectKey>/repos

 

(i) The authenticated user must have PROJECT_ADMIN permission for the parent project to be able to create a repository.

 

There are various options that can be set while creating the repository depending on the content of the input.json file.

 

Straightforward creation

At a minimum, the input file has to contain the name of the repository:

{
"name": "My Repository"
}

 

Publicly accessible repository

To enable the "Public access" while creating the repository, this is how to define the payload:

{
"name": "My Repository",
"public": true
}

Non forkable repository

A non forkable repository ("Allow forks" option unchecked) is created by using this input file:

{
"name": "My Repository",
"forkable": false
}

 

Reference documentation

5 comments

Travis_Cottreau
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!
May 1, 2019

Is there a full list of repository settings somewhere?

I am trying to change "pull requests"->"Unapprove automatically on new changes" to true, but have no idea where to find this parameter.

Like gabe stepanovich likes this
code
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!
October 3, 2019

Is this still working ? Lately I keep getting 

{"type": "error", "error": {"message": "Resource removed", "detail": "This API is no longer supported.\n\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"}}
Caterina Curti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 3, 2019

Hi @bunlongheng

This article is about Bitbucket Server & Data Center while I see you are trying to create a repository in Bitbucket Cloud (bitbucket.org).

This is the end point that can be used to create a repository in Bitbucket Cloud, in particular you want to use the POST method:

/2.0/repositories/{username}/{repo_slug}

 

Here is the link to the related documentation:

/2.0/repositories/{username}/{repo_slug}

james.mckean June 18, 2021

I am following this process to create a repo in BB Data Center 7.7.1.   When I use curl I get a 404 Error.

My command is:

curl --user <user>:<password> -H "Content-Type: application/json" --data @input.json -X POST https://bamboo.dev.<clientCompany>/rest/api/1.0/projects/<projectKey>/repos

input.json only contains the name line in the format above

Error message is: 

"null for uri: https://bamboo.dev.<clientCompany>.com/rest/api/1.0/projects/<MyExistingProjectKey>/repos"

Ideas?

Devashish Nigam
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!
January 5, 2024

How do I create repo with default branch as master instead of main

POST: rest/api/1.0/projects/<project_name>/repos

    {
    "name": "demo1",
    "scmId": "git",
    "forkable": true
    }

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events