Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

rest - How to add work item as child to parent?

I've been able to find documentation on creating work items via the VSTS REST API, however, I haven't been able to find anything creating a work item and linking it to a Parent work item.

Searching around, I've seen some links regarding a System.LinkTypes.Hierarchy-Reverse, but no API reference on how it works, or how it might link a work item to a parent work item id. Link here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To add a work item with parent work item linked, you should use the REST API as:

POST https://{accountName}.visualstudio.com/{project}/_apis/wit/workitems/${type}?api-version=4.1

application/json-patch+json:

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "title"},
    {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "System.LinkTypes.Hierarchy-Reverse",
      "url": "URL for the parent work item"
    }
    }

]

Below is the example to create a task mytask with parent work item (work item id is 184) linked:

POST https://marinaliu.visualstudio.com/Git2/_apis/wit/workitems/$Task?api-version=4.1

application/json-patch+json:

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "mytask"},
    {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "System.LinkTypes.Hierarchy-Reverse",
      "url": "https://marinaliu.visualstudio.com/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/wit/workItems/184"
    }
    }

]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...