“SPO licence” error using Graph API with Azure AD B2C

Image showing “Microsoft Graph API”

I was playing around with the code sample mentioned here to display the attributes of some B2C users.

“This .NET Core console application demonstrates the use of the Microsoft Graph API to perform user account management operations (create, read, update, delete) within an Azure AD B2C directory. Also shown is a technique for the bulk import of users from a JSON file. Bulk import is useful in migration scenarios like moving your users from a legacy identity provider to Azure AD B2C”.

The commands are:

Command  Description
====================
[1] Get all users
[2] Get user by object ID
[3] Get user by sign-in name
[4] Delete user by object ID
[5] Update user password
[6] Create users (bulk import)
[7] Create user with custom attributes and show result
[8] Get all users (one page) with custom attributes
[9] Get the number of users in the directory
[help] Show available commands
[exit] Exit the program
-------------------------
Enter command, then press ENTER:

Command “1” to list all the users only displays a few attributes so I wanted to extend it to display more.

// Get all users
var users = await graphClient.Users
.Request()
.Select(e => new
{
e.DisplayName,
e.Id,
e.Identities,
e.AccountEnabled,
e.CreatedDateTime,
e.GivenName,
e.Mail,
e.OtherMails,
e.UserPrincipalName,
e.UserType,
//e.Birthday,
e.Authentication,
e.City,
e.CompanyName,
e.Country,
e.Department,
e.EmployeeHireDate,
e.EmployeeId,
//e.HireDate,
//e.OfficeLocation,
e.PasswordPolicies,
e.People,
e.PostalCode,
//e.PreferredName,
e.State,
e.StreetAddress,
e.Surname,

However, when I ran it I got the error:

“Tenant does not have a SPO licence”.

Googling this, it seems that “SPO” stands for “SharePoint Online”, and you need an Office 365 Business account to have it. WTF?

I found that if I commented out some attributes as above, the error disappeared. Go figure!

All good!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rory Braybrook

Rory Braybrook

514 Followers

NZ Microsoft Identity dude and MVP. Azure AD/B2C/ADFS/Auth0/identityserver. StackOverflow: https://bit.ly/2XU4yvJ Presentations: http://bit.ly/334ZPt5