Similar to the question posted here, I am trying to manage Azure DevOps work items via python.
The accepted answer refers to the official Azure DevOps Python API docs and some sample code which seems like it might be out of date.
Here is a simplified version of the script I am trying to run:
from azure.devops.connection import Connection
from azure.devops.v7_1.work_item_tracking import JsonPatchOperation
from msrest.authentication import BasicAuthentication
personal_access_token = "MY_PAT"
organization_url = f'https://dev.azure.com/{MY_ORG}'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
core_client = connection.clients.get_core_client() # core client --> used to get project
project = core_client.get_project(MY_PROJECT_ID)
wit_client = connection.clients.get_work_item_tracking_client() # work item tracking client
# this code is recycled from the azure example code posted above
def _create_work_item_field_patch_operation(op, field, value):
path = '/fields/{field}'.format(field=field)
return _create_patch_operation(op=op, path=path, value=value)
def _create_patch_operation(op, path, value):
patch_operation = JsonPatchOperation()
patch_operation.op = op
patch_operation.path = path
patch_operation.value = value
patch_operation._from = None
return patch_operation
patch_document = []
patch_document.append(_create_work_item_field_patch_operation('add', 'System.Title', "Testing"))
patch_document.append(_create_work_item_field_patch_operation('add', 'System.Description', "Hoping to create a new work item."))
wit_client.create_work_item(document=patch_document, project=project, type="Bug")
When I execute this code, I get the following error:
azure.devops.exceptions.AzureDevOpsClientRequestError: Operation returned a 400 status code.
I am wondering if anybody has insight into why I am receiving a 400 status code.