2

So, I need to define Link type (Child or Parent) and ID

Can't find what to add, but stackoverflow says: It looks like your post is mostly code; please add some more details. So i am adding details

def CreateBug(Title, Description, AssignedTo, Tag, LinkTo):
url = 'https://devops.xp2131231231aare.com:81/suort/Mart/_apis/wit/workitems/$Bug?api-version=5.1'

data = [
    {
    "op": "add",
    "path": "/fields/System.Title",
    "value": Title
    },
    {
    "op": "add",
    "path": "/fields/System.IterationPath",
    "value": "Maort\\201_02"
    },
    {
    "op": "add",
    "path": "/fields/System.AssignedTo",
    "value": AssignedTo
    },
    {
    "op": "add",
    "path": "/fields/System.Tags",
    "value": Tag
    },
    {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.ReproSteps",
    "value": Description
    }
]
r = requests.post(url, json=data,
    headers={'Content-Type': 'application/json-patch+json'},
    auth=(user_name_x, token_x))

res = r.json()
#pprint(res)

id_ = res['id']
return (id_)

ScreenShot

1 Answer 1

5

You can add the following request body when you create work items. Here are my samples:

Add a parent link:

{
  "op": "add",
  "path": "/relations/-",
  "value": {
    "rel": "System.LinkTypes.Hierarchy-Reverse",
    "url": "https://dev.azure.com/{Organization}/_apis/wit/workItems/{ID}",// Replace with your organization name and work item ID
    "attributes": {
      "comment": "Making a new link for the dependency"
    }
  }
}

Add a child link:

{
  "op": "add",
  "path": "/relations/-",
  "value": {
    "rel": "System.LinkTypes.Hierarchy-Forward",
    "url": "https://dev.azure.com/{Organization}/_apis/wit/workItems/{ID}",// Replace with your organization name and work item ID
    "attributes": {
      "comment": "Making a new link for the dependency"
    }
  }
}

Here are links to documentation (v7.1) which you can refer to:

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

Comments

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.