2

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://learn.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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
POVR2
  • 87
  • 10
  • Does this answer your question? [Azure Devops Area API](https://stackoverflow.com/questions/71500217/azure-devops-area-api) – Ecstasy Jun 02 '22 at 04:57
  • [Add Iterations to Azure DevOps via script](https://stackoverflow.com/questions/58909633/add-iterations-to-azure-devops-via-script), [How do you get available Iteration Paths from Azure DevOps Services REST API?](https://stackoverflow.com/questions/60483245/how-do-you-get-available-iteration-paths-from-azure-devops-services-rest-api) and [Having trouble Creating Work Item with Area Path using REST API](https://developercommunity.visualstudio.com/t/having-trouble-creating-work-item-with-area-path-u/614608) – Ecstasy Jun 02 '22 at 04:57
  • @DeepDave-MT I've looked at all those links and have updated my question with a post request attempt, but i cant get the formatting to work so far – POVR2 Jun 09 '22 at 21:40
  • Have you checked similar issues and solutions? [How to update test results using azuredevops api](https://www.reddit.com/r/azuredevops/comments/pneogz/comment/hcw94fv/?utm_source=share&utm_medium=web2x&context=3), [Azure devops rest API postman error Value cannot be null.\r\nParameter name: TestPointUpdateParams](https://stackoverflow.com/questions/67963225/azure-devops-rest-api-postman-error-value-cannot-be-null-r-nparameter-name-tes) – Ecstasy Jun 10 '22 at 03:47
  • Alternatively, you can try using `ClassificationNodes`. [Azure DevOps Rest API - Unable To Create New Iteration](https://stackoverflow.com/questions/56247995/azure-devops-rest-api-unable-to-create-new-iteration) and [REST API error when creating a new iteration](https://social.msdn.microsoft.com/Forums/vstudio/en-US/c8b6126c-8eb4-4f24-978e-2a1dd1e27b9a/visual-studio-team-service-rest-api-error-when-creating-a-new-iteration?forum=vsx) – Ecstasy Jun 10 '22 at 03:59
  • Ive tried with that last link you sent, looks like they were using CLassificationNodes url in powershell. I tried moving it to python like so ```data = [ { "name":"Wk 18.02 - 18.03", "attributes":{ "startDate":"8 january 2018 GMT", "finishDate":"21 january 2018 GMT" } } ] response = requests.post( url="https://dev.azure.com/ADSP-Org-A03/RTC-ADS/_apis/wit/classificationNodes/Iterations/newIterationName?api-version=2.0", headers=headers, json=data )``` but it results in err Cannot deserialize the current JSON arr. – POVR2 Jun 10 '22 at 15:24
  • @POVR2 doesn the given answer work? – Abhinav Mathur Jun 16 '22 at 12:32

1 Answers1

1

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"
    }
}
Abhinav Mathur
  • 7,791
  • 3
  • 10
  • 24