Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 269
mchammerhead Avatar asked Aug 27 '26 15:08

mchammerhead


1 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

like image 100
nicolas.f.g Avatar answered Aug 30 '26 07:08

nicolas.f.g



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!