使用Powershell中的.json文件通过REST API更新Redmine Ticket

时间:2018-01-03 17:07:27

标签: json rest powershell

#Create an object to store the headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],
[String]]"
#Add Header Name, Value
$headers.Add("X-Redmine-API-key",'xxxxxxxxxxxxxxxxxxxxxx')
$headers.Add("Content-Type",'application/json')

$uri="https://redmine.company.com/issues"

$json=C:\scripts\ticket.json
#Calls the API 
Invoke-RestMethod -Method Put -Headers $headers -Uri $uri 


Invoke-RestMethod : Page not found
The page you were trying to access doesn't exist or has been removed.
Back
At line:21 char:8
+ $oData=Invoke-RestMethod -Method Put -Headers $headers -Uri $uri -
ContentType 'a ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: 
(System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : 

正如我在标题中所述,我试图使用REST API使用powershell更新带有json文件的票证。该错误声称我使用的URI不正确,但如果修改代码并使用GET,它就可以正常工作。有没有人试过这个或者有类似的东西我可以作为起点?

1 个答案:

答案 0 :(得分:0)

According to their documentation

Update: PUT update issue

$Headers = @{ 'X-Redmine-API-key' = 'xxx' }
$Body = Get-Content -Path C:\scripts\ticket.json -Raw
$Uri = 'https://redmine.company.com/issues/<ENTERIDHERE>.json'

$R = Invoke-RestMethod -Headers $Headers -Body $Body -Method PUT -Uri $Uri -ContentType application/json

$R