Microsoft Security | Microsoft Graph
An API that connects multiple Microsoft services, enabling data access and automation across platforms
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am working on a .NET application that interacts with the Microsoft Graph API to create users and send invitation emails. Below is my code snippet:
var user = new User
{
AccountEnabled = true,
JobTitle = "MyDealerID", // JobTitle property
DisplayName = $"{newUser.FirstName} {newUser.LastName}",
MailNickname = newUser.UserName,
UserPrincipalName = $"{newUser.UserName}@%**.onmicrosoft.com",
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = newUser.Password
}
};
// Adding OnPremisesExtensionAttributes (commented in the actual implementation for now)
//OnPremisesExtensionAttributes = new OnPremisesExtensionAttributes
//{
// ExtensionAttribute1 = "skypeId.adeleVance",
//};
try
{
// Option 1: Create the user directly (commented in actual implementation)
// var createdUser = await _graphClient.Users.PostAsync(user);
// Option 2: Send invitation email
var invitation = new Invitation
{
InvitedUser = user,
InvitedUserType = "Member",
InvitedUserEmailAddress = newUser.Email,
InviteRedirectUrl = "index.html",
SendInvitationMessage = true,
InvitedUserDisplayName = $"{newUser.FirstName} {newUser.LastName}"
};
var invitationResponse = await _graphClient.Invitations.PostAsync(invitation);
}
catch (Exception ex)
{
// Handle exceptions
}
await _graphClient.Users.PostAsync(user); to create a user, both JobTitle and OnPremisesExtensionAttributes are successfully created.Invitation endpoint via await _graphClient.Invitations.PostAsync(invitation);, these properties are not set in the created user object.await _graphClient.Users.PostAsync(user);, two users are created, which is not desirable.JobTitle and OnPremisesExtensionAttributes are included in the user created via the Invitation endpoint?Invitations endpoint does not support additional attributes directly.User object passed to Invitation.InvitedUser.Any insights or workarounds for this issue would be greatly appreciated!