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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.