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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,455,950
Community Members
 
Community Events
176
Community Groups

How do I create a new repo via 2.0 API and powershell?

I've read the documentation, and I've formatted my request body just like in the example with 1 addition: 

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization' , "$apiKey")
$headers.Add('accept', 'application/json')
$body=@"
{
"scm": "git",
"project": {
"key": "$MYKEY",
},
"is_private":$true
}
"@

try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod -Method PUT -Headers $headers -Body $body -Uri https://api.bitbucket.org/2.0/repositories/$workspace/$repoName -Verbose -UseBasicParsing
} catch {
echo "Something occured"
echo $_.Exception
echo $_
}

No matter what I put in the body, regardless of whether or not it's valid JSON, I always get a 200 response, the project KEY is wrong (defaults to oldest project in account), and it's not marked as a private repo. 

How am I supposed to format this request so that it works in powershell? 

1 answer

0 votes
Syahrul Atlassian Team Jan 12, 2022

Hey @ithryeandeus 

G'Day!

Have you tried adding the key manually for example as below:

{
    "scm": "git",
    "project": {
        "key": "TST"
    } 

Let me know if the scripts works and if it's still returning an error please share with us the full error. 

Additionally, if you wish to make your repositories private when created add the following additional parameter which should make it private:

{
    "scm": "git",
    "is_private": true,
    "project": {
        "key": "MARS"
    } 

Also, do check our newly update API page for more information on recent changes at:

I would also want to share the full curl commands so you have an idea of how the JSON data works in Bitbucket API:

curl -X POST -u "$BITBUCKET_USERNAME:$BITBUCKET_APPPASSWORD" "https://api.bitbucket.org/2.0/repositories/<Workspacename>/<Repositoriesname>" -H "Content-Type: application/json" -d '{"scm": "git", "is_private": true, "project": {"key": "TST"}}'

I hope this helps.

Cheers,
Syahrul

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events