Creating a workitem in Azure DevOps via python

Viewed 7771
2 Answers

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

Related