LepardUK
LepardUK

Reputation: 1360

How can I use TFS WebApi to remove a workitemlink

I am using Microsoft.TeamFoundation.WorkItemTracking.WebApi and trying to add and remove a workitemlink from an item.

I am calling

workItemTrackingHttpClient.UpdateWorkItemAsync(jsonPatchDocument, Id);

and my JsonPatchDocument looks like this.

[
  {
    "op": 1,
    "Path": "/relations/-",
    "From": null,
    "Value": {
      "Rel": "System.LinkTypes.Dependency-Forward",
      "Url": "https://[server]/tfs/DefaultCollection/_apis/wit/workItems/[id]"
    }
  }
]

When I use "op": 0 to update (add) it works correctly but I cannot work out the correct form for remove.

I get an error similar to

VssServiceException

Remove does not support insert. Microsoft.VisualStudio.Services.WebApi -2146232832

Anyone have any ideas please.

Upvotes: 1

Views: 919

Answers (1)

Tingting0929
Tingting0929

Reputation: 4192

To remove a link, the JsonPatchDocument is not like the insert, it is necessary to provide "value".

It is like:

[
  {
    "op": "test",
    "path": "/rev",
    "value": 3
  },
  {
    "op": "remove",
    "path": "/relations/0"
  }
]

To remove a link, you need to point which link to be removed by using "relations/Id". The Id is started from 0.

For more induction, please refer to the official document.

Upvotes: 3

Related Questions