Issue with JobTitle and OnPremisesExtensionAttributes not created when using Microsoft Graph API Invitations endpoint

Sunil Yadav 0 Reputation points
2024-11-15T12:22:48.15+00:00

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

}

Issue:

  1. When I use await _graphClient.Users.PostAsync(user); to create a user, both JobTitle and OnPremisesExtensionAttributes are successfully created.
  2. However, when I use the Invitation endpoint via await _graphClient.Invitations.PostAsync(invitation);, these properties are not set in the created user object.
  3. If I uncomment await _graphClient.Users.PostAsync(user);, two users are created, which is not desirable.

What I Need:

  • How can I ensure that properties like JobTitle and OnPremisesExtensionAttributes are included in the user created via the Invitation endpoint?
  • Is there a way to merge the functionality of user creation with these properties and sending the invitation in one step?

Attempts So Far:

  • I reviewed the Microsoft Graph API documentation, but it seems the Invitations endpoint does not support additional attributes directly.
  • I've also tried setting these properties on the User object passed to Invitation.InvitedUser.

Any insights or workarounds for this issue would be greatly appreciated!


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,528 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.