Unable to list Azure DevOps Organization by Azure DevOps REST API using Service Principal returns empty list

Gopalakrishnan G 0 Reputation points
2025-03-21T07:36:04.85+00:00

Issue Summary:

I am trying to access Azure DevOps resources using the REST API with authentication via a Service Principal (SPN) created under the same Azure Tenant. Despite granting all necessary permissions, I am unable to retrieve the list of Azure DevOps organizations the Service Principal is a member of. Instead, the API returns an empty list.

Steps Taken

  1. Added Service Principal as a User in Azure DevOps: The Service Principal has been successfully added as a user in my Azure DevOps organization.
  2. Obtained Access Token for the Service Principal: I generated an access token for Azure DevOps using the Service Principal credentials.
  3. Fetched memberID from the Profile API: I called the following API to retrieve the memberId: GET https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1 Reference: https://learn.microsoft.com/en-us/rest/api/azure/devops/profile/profiles/get?view=azure-devops-rest-7.1&tabs=HTTP profile id The API successfully returned a valid memberId.
  4. Tried Listing Azure DevOps Organizations: Using the retrieved memberId, I called the following API to list all organizations associated with the Service Principal: GET https://app.vssps.visualstudio.com/_apis/accounts?memberId={memberId}&api-version=7.1 Reference: https://learn.microsoft.com/en-us/rest/api/azure/devops/account/accounts/list?view=azure-devops-rest-7.1&tabs=HTTP acc Issues: The API returns an empty list ([]) even though the Service Principal is a user in Azure DevOps. I've given all the permission associated with the Service Principal even though it fails. And I have tried with the Personal Access Token, it works fine. but, with Service Principal it always returns an empty array.
    1. Why does the Service Principal fail to list the Azure DevOps organizations, while a Personal Access Token works? Are there additional permissions or configurations required for a Service Principal to access this API successfully?
    2. How can I list the Azure DevOps organizations that my Service Principal has access to or is a member of using the REST API?
    Any insights or solutions would be greatly appreciated!
Azure DevOps
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2025-03-26T12:01:10.0433333+00:00

    Hi Gopalakrishnan G, collating the discussed steps in a single answer for ease of documentation.

    As already discussed, in my case No other permission is required.

    In my case I added Service Principal as Project Contributors under the Organization settings:

    enter image description here

    Generated access token like below:

    
    GET https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
    
    client_id: ClientID
    
    client_secret: Secret
    
    scope: 499b84ac-1321-427f-aa17-267ca6975798/.default
    
    grant_type: client_credentials
    
    

    enter image description here

    When called the List accounts API, got empty response:

    
    GET https://app.vssps.visualstudio.com/_apis/accounts?memberId={memberId}&api-version=7.1
    
    

    enter image description here

    Unfortunately, Service Principal is not supported for calling the list Accounts API.

    Alternatively, you can make use of below API to call Azure DevOps Organizations using call the EnterpriseCatalog API:

    
    GET https://aexprodweu1.vsaex.visualstudio.com/_apis/EnterpriseCatalog/Organizations?tenantId=TenantID
    
    

    enter image description here

    I also added API permission in the Microsoft Entra ID application like below:

    User's image

    If you are still facing any issue, I have reached out to you over private message so that I can guide you better for the particular step where you are failing. We can connect offline to resolve the issue.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.