Tushar Borchate
Tushar Borchate

Reputation: 91

TFS Update workitem error:You must pass a valid patch document in the body of the request

I am trying to update TFS work-item field using patch method with following data:

[{ "op": "add", "path": "/fields/System.Title", "value": "JavaScript implementation for Microsoft Account" }]

but it gives me following error:

You must pass a valid patch document in the body of the request. If I use "patch" method for create work-item it works but fails in case of update work-item.

Upvotes: 5

Views: 8055

Answers (2)

Marcos Leal
Marcos Leal

Reputation: 1

It may have to do with the version of the package you're using. The latest stable version on nuget.org for TFS APIs related components is 15.112.1. But it turns out that for TFS2017 up to the update 2 all the 15.something and above versions of these packages won't work for any operation regarding PATCH operations. The last stable version compatible with TFS 2017 is the 14.102.0. This version works perfectly just like the documentation says it should.

Hope it helps.

Upvotes: 0

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31075

I have tested the PATCH method on my side, no issue occurs:

[
  {
    "method": "PATCH",
    "uri": "/_apis/wit/workItems/19?api-version=1.0",
    "headers": {
      "Content-Type": "application/json-patch+json"
    },
    "body": [
      {
        "op": "add",
        "path": "/fields/System.Title",
        "value": "JavaScript implementation for Microsoft Account"
      }
    ]
  }
]

Please check the example below which is used to update two work items to change their status to "Removed", then compare with your API to see whether there is something missing:

POST https://fabrikam.visualstudio.com/DefaultCollection/_apis/wit/$batch?api-version=1.0
Content-Type: application/json
[
  {
    "method": "PATCH",
    "uri": "/_apis/wit/workItems/284?api-version=1.0",
    "headers": {
      "Content-Type": "application/json-patch+json"
    },
    "body": [
      {
        "op": "add",
        "path": "/fields/System.State",
        "value": "Removed"
      }
    ]
  },
  {
    "method": "PATCH",
    "uri": "/_apis/wit/workItems/283?api-version=1.0",
    "headers": {
      "Content-Type": "application/json-patch+json"
    },
    "body": [
      {
        "op": "add",
        "path": "/fields/System.State",
        "value": "Removed"
      }
    ]
  }
] 

Upvotes: 1

Related Questions