Hi Guys,
I am working on script in python for adding multiple tasks in workitems in azure devops using rest - api please help me on this issue.
error - Error creating task: {"$id":"1","innerException":null,"message":"TF400813: The user 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' is not authorized to access this resource.","typeName":"Microsoft.TeamFoundation.Framework.Server.UnauthorizedRequestException, Microsoft.TeamFoundation.Framework.Server","typeKey":"UnauthorizedRequestException","errorCode":0,"eventId":3000}
code:-
import requests
import base64
def convert_to_base64(pat):
pat_bytes = pat.encode('ascii')
base64_pat = base64.b64encode(pat_bytes).decode('ascii')
return base64_pat
def create_task(organization, project, base64_token, workitem, title, description):
url = f"https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{workitem}?api-version=7.0"
headers = {
"Authorization": f"Basic {base64_token}",
"Content-Type": "application/json-patch+json",
}
data = [
{
"op": "add",
"path": "/fields/System.Title",
"value": title,
},
{
"op": "add",
"path": "/fields/System.Description",
"value": description,
},
]
response = requests.patch(url, headers=headers, json=data)
if response.status_code == 200:
print("Task created successfully!")
print(response.json())
else:
print("Error creating task: " + response.text)
if __name__ == "__main__":
organization = 'org'
project = 'proj'
work_item_id = id
personal_access_token = 'token'
title = "My task"
description = "This is my task description."
base64_token = convert_to_base64(personal_access_token)
create_task(organization, project, base64_token, work_item_id, title, description)