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.
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())
Comments
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.
2 Comments
mchammerhead
Great! Pointed me in the right direction, I appreciate it. I dont quite understand how to install those azure extension modules. It doesn't let me simple pip install azext_devops or anything like that. Is it something with the azure CLI that I'm supposed to install? I'm super confused...
PatrickLu-MSFT
@mchammerhead Sorry, not quite familiar with Python. But according to the description. The Azure DevOps Extension for Azure CLI adds Pipelines, Boards, Repos, Artifacts and DevOps commands to the Azure CLI. This commands are used to handle some Azure DevOps internal operation. You may need to install Azure CLI. Besides, you could also have a look at Python samples for Azure DevOps This repository contains Python samples that show how to integrate with Azure DevOps and Team Foundation Server (TFS) using the Azure DevOps Python API.