microsoft / azure-devops-python-api

Azure DevOps Python API
https://docs.microsoft.com/azure/devops/integrate/index?view=azure-devops
MIT License
584 stars 200 forks source link

Sample code for create work item #226

Closed corbyjames closed 5 years ago

corbyjames commented 5 years ago

Hi can someone post a code snippet for work item creation? When I do the following, I get an error on the JsonPatchObject.

op = WorkItemFieldOperation(name='add') jsonPatch = JsonPatchOperation(from_=None,op=op,path="/fields/System.Title",value="Test") tWorkItem = work_tracker_client.create_work_item(document=jsonPatch,project="BlueKC_Test",type='Epic',validate_only=None, bypass_rules=None, suppress_notifications=None,expand=None)

get this error:

TypeError: 'JsonPatchOperation' object is not iterable

Thanks!

corbyjames commented 5 years ago

Looking at some C# code examples, it looks like JsonPatchDocument is missing from the work_item_tracking models. Have you tested the create work item method?

It looks like the C# library at least, creates a JsonPatchDocument and then adds JsonPatchOperations to it, thus making it iteratable. If I'm missing something, let me know. The method to create a work item above fails in the recursive _validate method of the serialization file.

tedchamb commented 5 years ago

Here is some example code from the azure-devops-cli-extension:

https://github.com/Azure/azure-devops-cli-extension/blob/768aff8971aad2e194fa26d796d47b3a67292b4e/azure-devops/azext_devops/dev/boards/work_item.py#L24

corbyjames commented 5 years ago

Thanks Ted! It makes sense that the document is just a list of operations.