how to add azure devops iteration path option with python api

Viewed 157

I have an Azure DevOps project with multiple iteration paths: image

If I use this Azure Python API (https://github.com/microsoft/azure-devops-python-api) to create a new work item and set /fields/System.IterationPath to have a value that already exists like RTC-ADS\PI28\Sprint 28-3 it will create the work item with no issue.

But if I try to create a work item with an iteration that does not yet exist such as RTC-ADS\PI27 it will fail with an error

ERROR:root:Error creating ADS work item: TF401347: Invalid tree name given for work item -1, field 'System.IterationPath'.

I could create PI27 manually in my Azure Project settings, but is there a way I can use this Azure Python API to create a new iteration value for PI27 by making a POST request or something?

I have found documentation supporting how to do so I believe: https://docs.microsoft.com/en-us/rest/api/azure/devops/work/iterations/post-team-iteration?view=azure-devops-rest-6.0

But is it possible to add a new iteration value using this API? https://github.com/microsoft/azure-devops-python-api

Thanks

EDIT

I've been trying to get a POST request working to add a new iteration path:

pat = CONFIG.personal_access_token
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}

response = requests.post(
    url="https://dev.azure.com/ADSP-Org-A03/RTC-ADS/_apis/work/teamsettings/iterations?api-version=6.0&iteration=apple&startDate=2021-01-01&endDate=2021-01-11", 
    headers=headers
)

print(response.text)

But this results in an error:


{"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: iteration","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}

which i am trying to solve, is my request formatted incorrectly? I cant find a working example online for adding an iteration path to an ADS project

1 Answers

The first approach you've taken should be correct, but I think you're passing the request data incorrectly. It should be something like

pat = CONFIG.personal_access_token
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')

iteration_id = "" # add id here
headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}
attributes = {"startDate":"2021-01-01", "endDate": "2021-01-11"}
data = {"id": iteration_id, "attributes": attributes}

let url = "https://dev.azure.com/ADSP-Org-A03/RTC-ADS/_apis/work/teamsettings/iterations?api-version=6.0"
response = requests.post(url=url, headers=headers, json=data)

print(response.text)

Alternatively, for the classification nodes approach, the data you're using is incorrect. It should be

data = {
    "name":"Wk 18.02 - 18.03",
    "attributes": {
        "startDate":"8 january 2018 GMT",
        "finishDate":"21 january 2018 GMT"
    }
}
Related