OPEN TO WORK

Available for new opportunities! Let's build something amazing together.

Retrieving external / guest users via the Microsoft Graph API

API External users Guest users REST
post

This post is over a year old, some of this information may be out of date.

A project I was working involved retrieving all external / guest users that have been added to Office 365 and especially to Office 365 Groups. As it had to build in to an Office 365 application I choose to work with the Microsoft Graph.

First thing I did was retrieving all users with the standard API call:

API Call: https://graph.microsoft.com/v1.0/users

This is one of the results I got from the API call:

Show image User object from Microsoft Graph V1.0
User object from Microsoft Graph V1.0

As you can see, one of my guest users I have added is my professional account. All these external users have #EXT# in the userPrincipalName. First I thought to do a “contains” or “search” query, but it appears that is not yet possible.

When I went to check my Azure Active Directory users, I saw an interesting property: User Type.

Show image Azure AD User Identity
Azure AD User Identity

For all the external users in my environment this is set to Guest. The best news is, you can also query this property via the Microsoft Graph API.

If you want to retrieve all the external users inside your tenant, all you should do is user the following API call:

API Call: https://graph.microsoft.com/v1.0/users?$filter=userType eq ‘Guest’

Show image Guest user API call
Guest user API call

Beta endpoint

When I was writing this post, I found out that the beta endpoint gives you even more information about the user. This would have saved me some time today.

Show image User object in the beta endpoint
User object in the beta endpoint

Related articles

Report issues or make changes on GitHub

Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.

Comments

Elio Struyf

Solutions Architect & Developer Expert

Loading...

Let's build together

Manage content in VS Code

Present from VS Code