How to manage Azure DevOps project using REST API?
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In today’s blog post, we will discuss how to create, update, delete, and restore an Azure DevOps project programmatically using REST API.
How to manage Azure DevOps project using REST API?
Prerequisites:
How to create a new Azure DevOps project using REST API?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
## Define variables for authentication ORGANIZATION=" USER=$(az account show | jq -r .user.name) PAT=' ## Test if authentication working (List projects in your organization) curl -s -u $USER:$PAT \ https://dev.azure.com/$ORGANIZATION/_apis/projects?api-version=6.0 | jq . ## Create a new Azure DevOps project curl -s --request POST \ -u $USER:$PAT \ --header "Content-Type: application/json" \ --data '{ "name": "AzureDevOps", "description": "Azure DevOps Demo Project", "capabilities": { "versioncontrol": { "sourceControlType": "Git" }, "processTemplate": { "templateTypeId": "6b724908-ef14-45cf-84f8-768b5384da45" } } }' \ https://dev.azure.com/$ORGANIZATION/_apis/projects?api-version=6.0 | jq . |
How to get details on Azure DevOps project using REST API?
1 2 3 4 5 6 7 8 9 10 |
## List all Azure DevOps projects in your organization curl -s -u $USER:$PAT \ https://dev.azure.com/$ORGANIZATION/_apis/projects?api-version=6.0 | jq . ## Get project details PROJECT_ID=$(curl -s -u $USER:$PAT \ https://dev.azure.com/$ORGANIZATION/_apis/projects?api-version=6.0 \ | jq -r '.value[] | select(.name == "AzureDevOps") | .id') && curl -s -u $USER:$PAT \ https://dev.azure.com/$ORGANIZATION/_apis/projects/$PROJECT_ID?api-version=6.0 | jq . |
How to update an Azure DevOps project using REST API?
1 2 3 4 5 6 7 8 9 10 11 12 |
## Update Project's name, abbreviation, description curl -s --request PATCH \ -u $USER:$PAT \ --header "Content-Type: application/json" \ --data '{ "description": "New description of my project" }' \ https://dev.azure.com/$ORGANIZATION/_apis/projects/$PROJECT_ID?api-version=6.0 ## Get project details curl -s -u $USER:$PAT \ https://dev.azure.com/$ORGANIZATION/_apis/projects/$PROJECT_ID?api-version=6.0 | jq . |
Observe: Project description has been updated.
How to delete an Azure DevOps project using REST API?
1 2 3 4 5 6 7 8 9 |
## Delete the project curl -s --request DELETE \ -u $USER:$PAT \ --header "Content-Type: application/json" \ https://dev.azure.com/$ORGANIZATION/_apis/projects/$PROJECT_ID?api-version=6.0 ## List all Azure DevOps projects in your organization curl -s -u $USER:$PAT \ https://dev.azure.com/$ORGANIZATION/_apis/projects?api-version=6.0 | jq . |
Observe: The project has been deleted
How to restore an Azure DevOps project using REST API?
1 2 3 4 5 6 7 8 9 10 11 12 |
## Restore the project curl -s --request PATCH \ -u $USER:$PAT \ --header "Content-Type: application/json" \ --data '{ "state": "wellFormed" }' \ https://dev.azure.com/$ORGANIZATION/_apis/projects/$PROJECT_ID?api-version=6.0 ## List all Azure DevOps projects in your organization curl -s -u $USER:$PAT \ https://dev.azure.com/$ORGANIZATION/_apis/projects?api-version=6.0 | jq . |
Note: You can restore a deleted project up to 28 days after it was deleted.
Hope you have enjoyed this article. To know more about Azure DevOps, please refer below official documentation
https://docs.microsoft.com/en-us/azure/devops/?view=azure-devops