4
votes

I am attempting to create and then update an Azure Active Directory B2C user's profile. Here is how I create the user's profile following the Create User instructions, which works correctly:

 User newGuestUser = await graphClient.Users.Request().AddAsync(new User
 {
     AccountEnabled = true,
     DisplayName = guestUserProfile.Name,
     MailNickname = guestUserProfile.Organization,
     UserPrincipalName = guestUserProfile.Username + '@' + domain,
     UserType = "Guest",
     PasswordProfile = new PasswordProfile
     {
         Password = new NetworkCredential(string.Empty, guestUserProfile.Password).Password,
         ForceChangePasswordNextSignIn = true
     }
 });

Then, I attempt to update the user, and for example, add a user's "City" following the Update User instructions.

 // Update the user.
 await graphClient.Users[newGuestUser.Id].Request().UpdateAsync(new User
 {
      City = "Los Angeles",
      State = "CA"
 });

However, when I get the user object back with the code below, the "City" field is null? Why is this? How can I get the "City" field to say "Los Angeles"?

 newGuestUser = await graphClient.Users[newGuestUser.Id].Request().GetAsync();

Also, FYI, my graphClient's resource Id is https://graph.microsoft.com.

Looking at the Get User instructions, I need to use a $select statement. How do I do this with graphClient?

1
So Emilia, it looks like you answered your own question? You were able to successfully create a user, update the user and get back the properties you set, correct? Also is there a reason you are setting the userType to be a Guest?Dan Kershaw - MSFT
@DanKershaw-MSFT, yes I was able to answer my own question with some digging around. I would like this specific user to be a Guest; other users I would like to be Company Administrators. Is there a better method for creating Guest users?aBlaze
Answers go in the answer section, not the question (I have rolled back your changes). Either add your own answer and accept it to close this out, or accept the dupe.user3559349
Emilia - sorry for the late response. I get that you are trying to create Guest users :). The question is why are you trying to create Guest users in a B2C tenant - what is your scenario? Are you migrating existing social account users? Are these users from another tenant?Dan Kershaw - MSFT

1 Answers

1
votes

Looking at the Get User instructions, I need to use a $select statement.

var updatedUser = await graphClient.Users[newGuestUser.Id].Request().Select("City,State").GetAsync();