mchammerhead
mchammerhead

Reputation: 169

Creating a workitem in Azure DevOps via Python

Trying to create a new workitem in VSTS via Python API access and I cant find anywhere in the documents on how to create a new workitem in Python. I'm sure it's fairly simple but I can't seem to find it in the documentation.

https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/create?view=azure-devops-rest-5.1

Upvotes: 6

Views: 16926

Answers (2)

nicolas.f.g
nicolas.f.g

Reputation: 1241

Here is a solution for creating a new task, that relies only on the requests library:

import os
import requests

# See link down below to generate your Private Access Token
AZURE_DEVOPS_PAT = os.getenv('AZURE_DEVOPS_PAT')
url = 'https://dev.azure.com/xxxxxxxxxxx/xxxxxxxxxxxx/_apis/wit/workitems/$task?api-version=5.1'

data = [
 {
 "op": "add",
 "path": "/fields/System.Title",
 "value": "Sample task"
 }
]

r = requests.post(url, json=data, 
    headers={'Content-Type': 'application/json-patch+json'},
    auth=('', AZURE_DEVOPS_PAT))

print(r.json())

See Create personal access tokens to authenticate access

Upvotes: 11

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51093

Please kindly refer this official Azure DevOps Python API doc.

It contains Python APIs for interacting with and managing Azure DevOps. These APIs power the Azure DevOps Extension for Azure CLI. To learn more about the Azure DevOps Extension for Azure CLI, visit the Microsoft/azure-devops-cli-extension repo.

Here is some example code for creating work item in python.

Upvotes: 6

Related Questions