我正在尝试通过powershell和VSTS API编辑VSTS维基页面,我使用this documentation作为参考 .
当我尝试编辑现有页面时,出现以下错误:
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"The page '<PAGE That I CREATED ALREADY>' specified in the add operation already exists in the wiki. Please specify a new page path.","typeName":"Microsoft.TeamFoundation.Wiki.Server.WikiPageAlreadyExistsException, Microsoft.TeamFoundation.Wiki.Server","typeKey":"WikiPageAlreadyExistsException","errorCode":0,"eventId":3000}
At line:32 char:11
+ $result = Invoke-RestMethod -Uri $uri -Method Put -ContentType "appli ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
我可以在那里创建一个包含内容的新页面,但我很难过如何更新现有的wiki页面 . 请帮忙 .
我的代码片段:
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
# updates wiki page
$uri = "https://$($vstsAccount).visualstudio.com/$($projectName)/_apis/wiki/wikis/$($wikiIdentifier)/pages?path=/$($existingPage)&api-version=4.1"
$body = @"
{
"content": "Hello"
}
"@
$result = Invoke-RestMethod -Uri $uri -Method Put -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body -Verbose
3 回答
我可以建议一种不同的方法吗?
VSTS Wiki的存储是一个Git仓库(见here) . 因此,您可以克隆存储库,更改文件并推送更改 .
您甚至可以使用VSTS构建:克隆是隐式的,并且有许多扩展来实现推送 .
确保页面版本包含在请求标头中 . 有关详细信息,请参阅此链接:Pages - Create Or Update .
作为开发者社区中的帖子Update wiki page REST API can not working,请确保
If-Match
包含在请求标头中 .