6

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

2 Answers 2

11

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

Sign up to request clarification or add additional context in comments.

Comments

6

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

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...
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.