我已成功使用JIRA的Cloud Restful API执行GET和DELETE调用,但是在尝试使用POST将用户添加到群组时,我一直遇到错误。
相同的调用在POSTMAN中可以正常工作,但在Powershell中则不能。我怀疑这与我创建Bod的方式有关。
我尝试通过对键值对进行编码来修改$ Body,但没有成功:
[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$UserAccountID = '8675309'
$Body = @{
accountId = $UserAccountID
}
$ExternalGroupName = 'external-users'
$AddToExternalGroup = Invoke-RestMethod ('https://aquaman.jira.com/rest/api/3/group/user?groupname=' + $ExternalGroupName + '&accountId=' + $UserAccountID ) -Headers $Headers -Method POST -ContentType "application/json" -Body $Body
$AddToExternalGroup
我希望呼叫能像邮递员一样进行,但我收到此错误消息:
Invoke-RestMethod : {"errorMessages":["Unexpected character ('a' (code 97)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@5fe6ff6b; line: 1, column: 2]"]}
At line:2 char:31
+ ... rnalGroup = Invoke-RestMethod ('https://aquaman.jira.com/rest/api/3 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Method: POST, Reque\u2026application/json
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
答案 0 :(得分:2)
已修复!毕竟这是$Body
的问题。在遵循@AdminOfThings关于使用convertto-Json
的建议之后,剩下的就是要确保我没有将值用引号引起来。谢谢!