如何使用PowerShell在VSO项目中创建工作项

时间:2015-07-07 07:37:18

标签: rest powershell azure-devops

如何使用rest API在Visual Studio Online项目中创建新工作项。这是我对here

所述的期望
$task = @{"op"="test task";"path"="/rev";"value"=1}
$json = $task | ConvertTo-Json
$response = Invoke-RestMethod -Uri $apihref/wit/workitems/$Task?api-version=1.0 -Body $json -headers $h -Method PATCH

但会产生错误:Invoke-RestMethod : The remote server returned an error: (404) Not Found.

1 个答案:

答案 0 :(得分:0)

好的,我明白了。首先,我需要在$ Task之前筛选符号`。其次,我必须使用字段数组(不像一个字段)

$ wi = @(@ {“op”=“add”;“path”=“/ fields / System.Title";"value"="来自REST API的测试任务”}     ,@ {“op”=“add”; “path”=“/ fields /System.AssignedTo";"value"="Andrew Butenko”})

$ json = @($ wi)|的ConvertTo JSON的

$ response = Invoke-RestMethod -Uri“$($ collectionHref)/ $($ projectName)/ _ apis / wit / workitems /`$ Task?api-version = 1.0”-Body $ json -headers $ h -Method PATCH -ContentType“application / json-patch + json”