通过VSTS API编辑VSTS Wiki页面 [英] Edit VSTS Wiki page via VSTS API

查看:117
本文介绍了通过VSTS API编辑VSTS Wiki页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Powershell和VSTS API编辑VSTS Wiki页面,并且正在使用

I am trying to edit a VSTS wiki page via powershell and VSTS API and I am using this documentation as a reference.

当我尝试编辑现有页面时,出现以下错误:

When I try to edit an existing page, I get the following error:

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页面而感到困惑.请帮忙.

I can create a new page with the content there, but I am stumped as how would I update an existing wiki page. Please help.

我的代码"摘要:

    $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

推荐答案

作为帖子

As the post Update wiki page REST API can not working in developer community, please make sure If-Match is contained in request header.

这篇关于通过VSTS API编辑VSTS Wiki页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆