简体   繁体   English

Powershell - Bitbucket

[英]Powershell - Bitbucket

I'm probably missing something really simple here.我可能在这里遗漏了一些非常简单的东西。 I have the following powershell with nested jsons on the body.我有以下 powershell 与身体上的嵌套 jsons。

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...据我所知,项目是一个具有“关键”属性的 object ...

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.如果您不将其转换为 JSON,那么它仍然是 PowerShell object。

Invoke-RestMethod:调用-RestMethod:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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