我试图通过PowerShell和VSTS API编辑VSTS维基页面和我使用这个文件作为参考。
当我尝试编辑已有的页面,我得到以下错误:
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
我可以创建一个内容出现了新的一页,但我难倒,因为我将如何更新现有的维基页面。 请帮忙。
我的代码的片段:
$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