How to get Project ID in Azure DevOps

Whether you’re a developer, a project manager, or an IT professional, this guide is just for you. We’ll explore several methods, discuss their pros and cons, and ensure you walk away with a robust understanding of how to get Azure devops project id.

How to get Project ID in Azure DevOps

Method 1: Using the Azure DevOps REST API – For the Power User

For those who frequently work with automation, scripting, or custom integrations, using the Azure DevOps REST API to fetch the Project ID is an incredibly powerful and efficient method. This is where you truly harness the programmatic capabilities of Azure DevOps.

To use the API, you’ll need a Personal Access Token (PAT) with sufficient permissions (at least “Project and Team (Read)” scope) or an OAuth 2.0 authorization flow. For simplicity, this tutorial focuses on using a PAT.

Prerequisites:

  • Personal Access Token (PAT): Create a PAT in Azure DevOps (User settings -> Personal access tokens). Ensure it has the “Project and Team (Read)” scope.
  • HTTP Client: Tools like Postman, Insomnia, curl, or even a simple script using Invoke-RestMethod (PowerShell) or requests (Python) can be used.

API Endpoint:

The core API endpoint to list projects within an organization is:

GET https://dev.azure.com/{organization}/_apis/projects?api-version=7.1-preview.4

Example

https://dev.azure.com/fewlines4biju/_apis/projects/TeamTsinfo?api-version=7.1

Copy and paste this url in your browser. See the screenshot below, we got the expected output, and the project ID is highlighted in red.

azure devops get project id

Step-by-step with curl (command-line tool):

  1. Obtain your PAT: Let’s say your PAT is your_personal_access_token.
  2. Construct the curl command:Bashcurl -u :{your_personal_access_token} \ https://dev.azure.com/{your_organization_name}/_apis/projects?api-version=7.1-preview.4 \ -H "Accept: application/json"
    • Replace {your_personal_access_token} with your actual PAT.
    • Replace {your_organization_name} with your Azure DevOps organization’s name (e.g., TechSolutionsUSA).
    • The -u flag with :{PAT} tells curl to use the PAT for basic authentication without a username (the colon before the PAT is crucial).
  3. Execute the command: Run this command in your terminal.
  4. Parse the JSON Response: The API will return a JSON array of all projects within your organization. Each project object will contain its name, description, and, crucially, its id (which is the Project ID GUID).
  5. Example JSON Snippet (simplified):JSON{ "count": 2, "value": [ { "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "name": "NorthwindTraders", "description": "E-commerce solutions for a global market", "url": "https://dev.azure.com/TechSolutionsUSA/_apis/projects/a1b2c3d4-e5f6-7890-1234-567890abcdef", "state": "wellFormed", "revision": 123 }, { "id": "f0e9d8c7-b6a5-4321-fedc-ba9876543210", "name": "ProjectPhoenix", "description": "Next-gen internal tools development", "url": "https://dev.azure.com/TechSolutionsUSA/_apis/projects/f0e9d8c7-b6a5-4321-fedc-ba9876543210", "state": "wellFormed", "revision": 456 } ] } From this response, you can easily identify the id field corresponding to your project’s name.

Pros:

  • Automation-Friendly: Ideal for scripts, CI/CD pipelines, and integrating with other systems.
  • Programmatic Access: Allows for dynamic retrieval of Project IDs without manual intervention.
  • Comprehensive: Can retrieve details for all projects in an organization.

Cons:

  • Requires Setup: Needs a PAT and familiarity with API calls or scripting.
  • Learning Curve: Steeper learning curve for beginners compared to UI methods.
  • Security Consideration: Managing PATs requires careful attention to security.

Method 2: Azure DevOps CLI

For those who love working in the terminal and managing Azure resources via the command line, the Azure DevOps CLI extension is a powerful tool. It provides a consistent and efficient way to interact with your Azure DevOps organizations and projects.

Prerequisites:

  • Azure CLI Installed: You need the Azure Command-Line Interface installed on your machine.
  • Azure DevOps Extension: Install the Azure DevOps extension for the Azure CLI. If you haven’t already, run:az extension add --name azure-devops
  • Logged In: Ensure you are logged into Azure CLI with an account that has access to your Azure DevOps organization.az login
  • Set Default Organization (Optional but Recommended): To simplify commands, set your default Azure DevOps organization:az devops configure --defaults organization=https://dev.azure.com/{your_organization_name}

Step-by-step to get Project ID:

List all Projects under a specific Organization

az devops project list --org https://dev.azure.com/YourOrgName --output table

Example

az devops project list --org https://dev.azure.com/fewlines4biju --output table

After executing the above query, I got the expected output as shown in the screenshot below

how to get project id in azure devops

Filtering for a specific project:

You can also filter the output using JMESPath queries directly within the CLI to get just the ID for a known project name:

az devops project show --project "TeamTsinfo" --org https://dev.azure.com/fewlines4biju --query id

After executing the above query, I got the expected output as shown in screenshot below

how to get azure devops project id
  1. List Projects: Use the az devops project list command to get a list of all projects in your configured organization.Bashaz devops project list --output json
    • The --output json flag will give you a JSON output, which is easy to parse. You can also use --output table for a more human-readable format, but it might not show the GUID explicitly.
  2. Identify the Project ID: In the JSON output, each project will have an id field. Locate the project you’re interested in by its name and then copy its corresponding id.
  3. Example Output Snippet (simplified):JSON[ { "abfUri": "vstfs:///Classification/TeamProject/a1b2c3d4-e5f6-7890-1234-567890abcdef", "description": "E-commerce solutions for a global market", "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "lastUpdateTime": "2023-10-26T10:00:00.000Z", "name": "NorthwindTraders", "properties": [ // ... other properties ], "revision": 123, "state": "wellFormed", "url": "https://dev.azure.com/TechSolutionsUSA/_apis/projects/a1b2c3d4-e5f6-7890-1234-567890abcdef", "visibility": "private" }, { "id": "f0e9d8c7-b6a5-4321-fedc-ba9876543210", "name": "ProjectPhoenix", // ... } ] As you can see, the id field directly provides the Project ID.

Pros:

  • Command-Line Efficiency: Great for terminal users and scripting.
  • Consistent Interface: Part of the broader Azure CLI ecosystem.
  • Powerful Filtering: JMESPath queries allow for precise data extraction.

Cons:

  • Requires Installation: Azure CLI and the DevOps extension must be installed.
  • Authentication: Requires logging in to Azure CLI.
  • Learning Curve: Less intuitive for those unfamiliar with command-line tools.

Method 3: Using PowerShell

We can use the PowerShell script below to retrieve the project ID for your Azure DevOps project.

# Define variables
$orgName = "fewlines4biju"
$projectName = "TeamTsinfo"
$pat = "9llg5jenochbEGi4NkfiYaUcYMbYnzcyLoqbNMvwVRMxtlkUQY04JQQJ99CAACAAAAAAAAAAAAASAZDO2aIU"

# Create Authorization Header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat"))
$headers = @{Authorization = "Basic $base64AuthInfo"}

# API URL to get project details
$url = "https://dev.azure.com/$orgName/_apis/projects/$($projectName)?api-version=7.1"

try {
    $response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
    $projectId = $response.id
    Write-Host "The Project ID for '$projectName' is: $projectId" -ForegroundColor Cyan
}
catch {
    Write-Error "Failed to retrieve project. Check your Project Name, Org, or PAT."
}

After executing the above script, I got the expected output as shown in the screenshot below.

how to get project id in azure devops using powershell

Best Practices for Handling Project IDs

Now that you know how to find your Project ID, let’s touch on a few best practices to ensure you’re using this information effectively and securely:

  • Don’t Hardcode in Production: While it’s okay for quick tests, avoid hardcoding Project IDs directly into production scripts or applications. Instead, use environment variables, configuration files, or better yet, retrieve them dynamically using the API or CLI based on the project name. This makes your solutions more flexible and easier to maintain.
  • Manage PATs Securely: If you’re using PATs for API or CLI access, treat them like passwords. Store them securely, rotate them regularly, and grant them only the minimum necessary permissions (e.g., “Project and Team (Read)” for just getting the ID).
  • Document Your Projects: Especially in larger organizations with many projects (I’m looking at you, enterprise teams across the US!), maintain a document or wiki that lists project names alongside their IDs. This serves as a quick reference for your team.
  • Understand the Difference: Name vs. ID: Always remember that a Project Name is human-readable and can sometimes change (though it’s rare and discouraged once a project is mature). The Project ID (GUID) is the immutable, unique identifier that Azure DevOps uses internally. When building automated solutions, always prioritize using the ID.

Video Tutorial

Conclusion:

Getting your Azure DevOps Project ID is a fundamental skill that every Azure DevOps developer needs to know. Mastering these methods will make your workflow smoother and more powerful.

You may also like the following articles:

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!