通过VSTS API编辑VSTS Wiki页面

时间:2018-07-06 19:11:58

标签: api azure-devops azure-pipelines-release-pipeline azure-devops-rest-api

我正在尝试通过powershell和VSTS API编辑VSTS Wiki页面,并且我使用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 个答案:

答案 0 :(得分:1)

作为开发者社区中的帖子Update wiki page REST API can not working,请确保If-Match包含在请求标头中。

答案 1 :(得分:0)

我可以建议其他方法吗?

VSTS Wiki的存储是Git存储库(请参见here)。因此,您可以克隆存储库,更改文件并将更改推回。

您甚至可以为此使用VSTS构建:克隆是隐式的,并且有许多扩展来实现推送。

答案 2 :(得分:0)

确保页面版本包含在请求标头中。有关详细信息,请参见此链接:Pages - Create Or Update

  

要进行更改的页面的版本。强制性   编辑方案。将填充到请求的If-Match标头中。

相关问题