Use the Rest API below to get all users within your organization (tenant) and their associated information about Microsoft Teams.
NOTE: Please note these APIs are used by the PowerShell team and TAC. They could change any moment. They are not supported by Microsoft. They are not supported by me. Use at your own risk.
Get a list of users
To get a list of users in the organization. Each command uses the prefix https://api.interfaces.records.teams.microsoft.com/ to access the resource. Each command must include the Authorization and X-MS-Target-Uri header. For more information about each of these, please see Authentication to Teams Admin API. For additional details, you can see the Swagger page, but in my testing a lot of the results specified don’t work or return values. This page is to try to give you a real world look at how to use this endpoint.
The following is an example of a response.
"displayName": "Alice Anderson",
...some removed for readability
In the above response, you can see we get the basic information about each user. We can use the select and filtering commands below. Here is a sample of what it looks like from Insomnia.
Filtering, Select and Other Options
This endpoint supports the following options:
Using standard OData filtering. See this Micorosft Graph Query Paramaters for some examples of OData filtering. These end points only support a small range of what can be used in MS Graph. Here are some working examples:
GET /Teams.User/users/?$filter=displayName eq 'Richard Brynteson'
Returns only records with the display name of Richard Brynteson
GET /Teams.User/users/?$filter=accountEnabled eq true
Returns only records where accountEnabled equals true
NOTE: OData requires the correct type of variable to be passed into it. For example, displayName is a string therefore you must pass a string wrapped in quotes. accountEnabled is a boolean so it must be true or false (lowercase). Do not wrap with quotes or it is a string and will fail.
Paging & Page Size
The API does support both page size and paging. Although there is something a bit strange with the page size function. If your request requires additional pages, you will be prompted with the @nextlink at the top of your return. You can then iterate on this link to get the next page size.
A few items of note. First, there is no need to place a $ in front of pagesize. If you like OData, you can substitute the ?pagesize=15 for ?$top=15 for the same results. They appear to work the same. What is more interesting to me is that the number of results returned is not correct, ever. For example, if you pass 5 into page size, in all cases, I was returned with 3 results. Lastly, the max page size you can enter is 999. At 1000 or above, the endpoint will return an error.
To setup paging support, you do need to include the $skiptoken so you can jump between pages. Because the above pagesize does not appear to ever give the correct number of results, there is no need to create your own paging functionality.
Using standard OData select statements, you can choose which items you would like to be returned in your request.
Returns only the selected fields. The result would look like:
"displayName": "AA Assistance Voicemail"
"displayName": "Alice Ahlstrom"
The following fields may be included in the select command. I have tested each of these and know they work. There are other items listed in the sample response but many do not work.
- alias (string)
- accountEnabled (bool)
- assignedLicenses (object array)
- assignedPlans (object array)
- businessPhones (string array)
- callingLineIdentity (object array)
- conferencingPolicy (object array)
- dialPlan (string)
- enterpriseVoiceEnabled (bool)
- externalAccessPolicy (object array)
- featureTypes (string array)
- givenName (string)
- hideFromAddressLists (bool)
- hostingProvider (string)
- interpretedUserType (string)
- Will also include
- teamsUpgradeNotificationsEnabled (string)
- teamsUpgradePolicyIsReadOnly (string)
- isResourceAccount (bool)
- isSipEnabled (bool)
- licenseAssignmentStates (object array)
- lineUri (string)
- mail (string)
- mailNickName (string)
- objectId (GUID)
- onlineVoiceRoutingPolicy (object array)
- provisionedPlans (object array)
- proxyAddresses (string array)
- registrarPool (string)
- serviceInstance (string)
- shadowProxyAddresses (string array)
- sipAddress (string)
- sipProxyAddress (string)
- surname (string)
- tenantId (GUID)
- usageLocation (string)
- userDirSyncEnabled (bool)
- userPrincipalName (string)
- onPremEnterpriseVoiceEnabled (bool)
- onPremDomainName (string)
- onPremSecurityIdentifier (string)
- onPremSamAccountName (string)
- directoryStatus (string)
- pstnConnectivity (string)
- userValidationErrors (string array)
And the following Teams Policies. You must have a policy assigned otherwise the item does not even return in the response. No null, or blank.
This endpoint does not support any OData sorting features.