Syed Mauze Rehan
Syed Mauze Rehan

Reputation: 1145

Get all domains for a tenant through REST API

I want to know if there is a way to retrieve the registered domain(s) for a tenant through REST API for Sharepoint/Office365.

Consider this scenario;

I have a tenant named abc.pqr and url for the "my" site(OneDrive) is abc-my.sharepoint.com.

Now when I create a user for this tenant, the UI panel gives the option to select a domain for this account. Available options are;

1) @abc.pqr
2) @abc.onmicrosoft.com

Now, the problem is, if I have a user of this sort >>> [email protected], how do I findout the registered domain for this tenant? Which in my case is abc.pqr.

Is there a way to find this through REST API?

Upvotes: 2

Views: 3444

Answers (1)

Philippe Signoret
Philippe Signoret

Reputation: 14336

Sounds like what you want to know is the list of verified domains in your Azure Active Directory tenant. (Azure AD is the directory service behind Office 365 and other Microsoft online services.)

The Azure AD Graph API—AAD's REST API—can provide this for you. In your case, the GET request you would want to make is:

https://graph.windows.net/abc.onmicrosoft.com/tenantDetails

Note: you can use either the tenant ID or any verified domain of the tenant instead of abc.onmicrosoft.com. The tenant ID can be obtained from the tid claim in the access token.

The JSON response will include something like this:

  "verifiedDomains": [
    {
      "capabilities": "None",
      "default": true,
      "id": "0007ABE0983098",
      "initial": false,
      "name": "abc.pqr",
      "type": "Managed"
    },
    {
      "capabilities": "Email, OfficeCommunicationsOnline",
      "default": false,
      "id": "0007ABE0983098",
      "initial": true,
      "name": "abc.onmicrosoft.com",
      "type": "Managed"
    }
  ]

(There's a useful Quickstart for the Azure AD Graph API that shows how to start playing around with AAD Graph API, and the GraphExplorer.)

If you're using .NET, there is a full sample at https://github.com/AzureADSamples/WebApp-GraphAPI-DotNet. (More samples for other languages and platforms at https://github.com/AzureADSamples.)

Upvotes: 4

Related Questions