4

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?

Saeed Akhter
  • 407
  • 3
  • 9
aBlaze
  • 2,436
  • 2
  • 31
  • 63
  • 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 Feb 11 '18 at 02:29
  • @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 Feb 11 '18 at 19:01
  • Possible duplicate of [Get all user properties from microsoft graph](https://stackoverflow.com/questions/48229949/get-all-user-properties-from-microsoft-graph) – Marc LaFleur Feb 12 '18 at 02:33
  • 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. –  Feb 12 '18 at 07:26
  • 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 Feb 18 '18 at 20:26
  • @DanKershaw-MSFT thanks for your reply! My original reason for creating a Guest user is because I thought that the Guest role was the only non-administrator option, and I wanted to create a non-admin user. However, now I see that there is a distinction between "User Types" (options: Guest & Member) and "Directory Roles" (options: Global Admin, Limited Admin, & User). – aBlaze Feb 22 '18 at 02:50

1 Answers1

1

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();
aBlaze
  • 2,436
  • 2
  • 31
  • 63