Reputation: 65
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.
Upvotes: 0
Views: 2674
Reputation: 35564
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:
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"
}
]
Upvotes: 1