Using VSTS Rest API, how do you Update a Markdown

2019-07-18 11:38发布

问题:

I'm trying to use this REST API to Update a "Markdown" widget on a dashboard in VSTS.

Using the below JSON body, per the sample, I'm getting Value cannot be null (see below)?

Error

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: widget","typeName":"System.ArgumentNullException,mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}At C:\Users\alex\OneDrive\Documents\Scripts\VSTSPowershell\VSTSAuthenticateAndInvoke.ps1:36 char:23+ ... $result = Invoke-RestMethod -Uri $uri -Method $method -ContentType ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

JSON

{
    "id": "3b52e9ed-576e-4985-82ae-8e80b22a4b4d",
    "eTag": "1",
    "name": "Markdown",
    "size": {"rowSpan":2; "columnSpan":2},
    "settings": "# AAAAK Markdown\nAdd content using the markdown widget.\n- **Bold**\n- *Italic*\n- [Links]()",
    "settingsVersion": "@{major=1; minor=0; patch=0}",
    "dashboard": {
        "eTag": "35"
      },
    "contributionId": "ms.vss-dashboards-web.Microsoft.VisualStudioOnline.Dashboards.MarkdownWidget"
}

Fiddler Request/Response

My goal is simply to find & update a Markdown widget with new display content. It's a newly created widget, so eTag=1, which I verified with a Get Dashboard along with the WidgetId, and the eTag=35 is what the Dashboard is.

回答1:

Change this line:

"size": {"rowSpan":2; "columnSpan":2},

to

"size": {"rowSpan":2, "columnSpan":2},