Home > OS >  How to get the tenant id with the azure-devops-extension-api and azure-devops-extension-sdk?
How to get the tenant id with the azure-devops-extension-api and azure-devops-extension-sdk?

Time:01-06

I have a small problem. I'm trying to get the tanant id. I tried to use code below but can only get project id.

import * as SDK from "azure-devops-extension-sdk";
import { CommonServiceIds, IProjectPageService } from "azure-devops-extension-api";
const projectService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
const project = await projectService.getProject();

Any ideas ?

CodePudding user response:

You can find tenant ID in Domain property of below DevOps API call response regarding Identities:

GET https://vssps.dev.azure.com/{organization}/_apis/identities?searchFilter=General&filterValue=<Azure AD username>&queryMembership=None&api-version=7.0

I tried to reproduce the same in my environment via Postman and got below results

To create new Personal access token (PAT), you can find below steps in your DevOps portal:

enter image description here

I generated one PAT token with full access for my DevOps organization like below:

enter image description here

When I ran below query including PAT token in Postman, I got tenant ID in response successfully like below:

GET vssps.dev.azure.com/{organization}/_apis/identities?searchFilter=General&filterValue=<Azure AD user UPN>&queryMembership=None&api-version=7.0

Response:

enter image description here

To confirm that, I checked the same in Azure DevOps portal and got same tenant ID like this:

enter image description here

Reference: IdentitySelf interface | Microsoft

  • Related