Azure Python how to link child/related tickets to an already created ticket?

%3CLINGO-SUB%20id%3D%22lingo-sub-3242980%22%20slang%3D%22en-US%22%3EAzure%20Python%20how%20to%20link%20child%2Frelated%20tickets%20to%20an%20already%20created%20ticket%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3242980%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20using%20the%20Azure%20Python%20tool%20to%20create%20Epic%2FStory%2FFeature%20work%20items%20in%20a%20python%20script%20like%20so%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%23%20add%20fields%0Ajpo%20%3D%20JsonPatchOperation()%0Ajpo.from_%20%3D%20None%0Ajpo.op%20%3D%20%22add%22%0Ajpo.path%20%3D%20%22%2Ffields%2FMicrosoft.VSTS.Scheduling.FinishDate%22%0Ajpo.value%20%3D%20default_field%0Ajpos.append(jpo)%0A%0A%23create%20work%20item%0AcreatedWorkItem%20%3D%20wit_client.create_work_item(%0Adocument%3Djpos%2C%0Aproject%3Dproject.id%2C%0Atype%3D%22EPIC%22%2C%0Avalidate_only%3Dvalidate_only%2C%0Abypass_rules%3Dbypass_rules%2C%0Asuppress_notifications%3Dsuppress_notifications%0A)%0A%0A%23save%20details%20to%20local%20json%20file%0Aepic_details%20%3D%20%7B%0A%22op%22%3A%20%22add%22%2C%0A%22path%22%3A%20%22%2Frelations%2F-%22%2C%0A%22value%22%3A%20%7B%0A%22rel%22%3A%20%22System.LinkTypes.Hierarchy-Reverse%22%2C%0A%22name%22%3A%20%22Parent%22%2C%0A%22url%22%3A%20createdWorkItem.url%0A%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20link%20my%20tickets%20together%2C%20such%20as%20adding%20a%20Child%20%2F%20Parent%20relationship%20between%20tickets.%20I'm%20trying%20to%20do%20this%20by%20creating%20all%20my%20tickets%20first%2C%20then%20linking%20them%20all%20where%20needed.%3C%2FP%3E%3CP%3EIs%20there%20some%20way%20with%20the%20Azure%20Devops%20Python%20tool%20that%20I%20can%20add%20a%20child%20workitem%20to%20a%20epic%20workitem%20if%20both%20tickets%20already%20exist%3F%20Thanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3242980%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Echild%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eepic%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eparent%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPython%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Estory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eworkitem%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

I am trying to use the azure-devops python pip package in order to migrate a large amount of Epic/Story/Feature tickets into Azure Devops. I can create singular tickets just fine, but I'm having trouble linking those tickets together by specifying the hierarchy (ticket A is a parent to child tickets B / C / D)

In order to create an EPIC ticket I'm running code like this:

#set field
jpo = JsonPatchOperation()
jpo.from_ = None
jpo.op = "add"
jpo.path = "/fields/Microsoft.VSTS.Scheduling.FinishDate"
jpo.value = default_field
jpos.append(jpo)

#create work item
createdWorkItem = wit_client.create_work_item(
document=jpos,
project=project.id,
type="EPIC",
validate_only=validate_only,
bypass_rules=bypass_rules,
suppress_notifications=suppress_notifications
)


Which works, but now I'm trying to figure out how to give this Epic ticket a linked Child ticket.

In the github repo for this azure-devops python package, I can see that in the definition for `create_work_item` there is a string variable `expand` which has an option for `Relations`

https://github.com/microsoft/azure-devops-python-api/blob/master/azure-devops/azure/devops/v5_1/work...

```
:param str expand: The expand parameters for work item attributes. Possible options are { None, Relations, Fields, Links, All }.
```
It's also discussed in the official azure-devops documentation for the create_work_item function:
https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/create?view=azure-devops-rest-...

But if I add `expand='Relations'` to my code it results in an error:

createdWorkItem = wit_client.create_work_item(
document=jpos,
project=project.id,
type="EPIC",
validate_only=validate_only,
bypass_rules=bypass_rules,
suppress_notifications=suppress_notifications,
expand='Relations'
)


`TypeError: WorkItemTrackingClient.create_work_item() got an unexpected keyword argument 'expand'`

Am I using this 'expand' variable correctly? Or is there a different way I should add a child ticket to an epic in azure using python? Thanks

1 Reply