0

I've been unable to find out how to update work item links using the Azure DevOps REST API. Does anyone know the REST command to use to do this? I'm thinking it may be possible to use the work item update patch call but not sure how to structure the body?

For example we can use the following call to update the OTLNumber field

PATCH: https://dev.azure.com/myorg/_apis/wit/workitems/1824160?api-version=6.0&bypassRules=True

Body:

[
  {
    "op": "test",
    "path": "/rev",
    "value": 3

  },
  {
    "op": "add",
    "path": "/fields/Custom.OTLNumber",
    "value": "35195"
  }
]

Something like this to set the 'tested by' link to the test case number 1824175?

[
  {
    "op": "test",
    "path": "/rev",
    "value": 1

  },
  {
    "op": "add",
    
    "path": "/relations/added.Microsoft.VSTS.Common.TestedBy-Forward",
    "value": "https://dev.azure.com/zionseto/_apis/wit/workItems/1824175"
  }
]

Any help would be appreciated. Having a hard time finding in their documentation.

1 Answer 1

1

You can try to use the following sample to add the TestBy links to work item.

Rest API URL:

Patch https://dev.azure.com/Org/_apis/wit/workitems/ID?api-version=6.0

Request Body:

[
  {
    "op": "test",
    "path": "/rev",
    "value": 2
  },
  {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "Microsoft.VSTS.Common.TestedBy-Forward",
      "url": "https://dev.azure.com/org/project/_apis/wit/workItems/1824175",

    }
  }
]

Update:

To remove the testby link, you first need to determine the position of the sequence where the testby work item is located.

Run the Following Rest API:

Get https://dev.azure.com/org/project/_apis/wit/workitems/ID?$expand=all&api-version=6.0

Then you can check the relations:

enter image description here

It is calculated from 0. For example: work item 913 is 0 , 920 is 1.

Then you can run the Rest API to remove the work item.

Rest API URL:

Patch https://dev.azure.com/Org/_apis/wit/workitems/ID?api-version=6.0

Request Body:

[
  {
    "op": "test",
    "path": "/rev",
    "value": 15
  },
  {
    "op": "remove",
    "path": "/relations/1"

  }
]
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you that did it!
Glad to know that it can work for you. If it can solve this issue , you may consider accepting this answer. This will be helpful to others who has the same issue. Thanks.
Thanks! do you know how to remove the link?
You can refer to my update to remove the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.