简体   繁体   中英

Powershell - Bitbucket

I'm probably missing something really simple here. I have the following powershell with nested jsons on the body.

Invoke-RestMethod "https://api.bitbucket.org/2.0/repositories/myworkspace/$slug" -Body @{ "scm" = "git"; "project" = @{ "key" = $pkey }; } -Method Post -Headers @{Authorization = $cloudAuthHeader}

But the response I'm getting from the server is:

Invoke-RestMethod: {"type": "error", "error": {"fields": {"project": ["Project must be an object with a \"key\" or \"uuid\" property."]}, "message": "project: Project must be an object with a \"key\" or \"uuid\" property."}}

As far as I can tell, project is an object with a "key" property...

You can try:

$body = @{ "scm" = "git"; "project" = @{ "key" = $pkey }; } | ConvertTo-Json -Depth 99
$auth = @{Authorization = $cloudAuthHeader} | ConvertTo-Json 

Afaik if you don't convert it to JSON it is still a PowerShell object.

Invoke-RestMethod:

"https://api.bitbucket.org/2.0/repositories/myworkspace/$slug" -Body $body -Method Post -Headers $auth

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM