0
votes

I am trying to invite guest user in my Office 365 tenant using Azure AD B2B api and the intent is to set hireDate property of the guest user as soon as invitation is sent. For me its not necessary that guest should redeem the invitation. The problem is, code fails (with error message: Unable to check user existence in AD) when I am trying to patch user to update hireDate property irrespective of guest redeem the invitation or not. The problem does not occur if i wait for a minute or so after sending the invitation and then try to patch the user. How can I set this property without waiting?

To resolve this, i already tried implementing retry logic but this is not reliable.

var token = extranetHelper.GetAuthToken(); //Custom class to get token
var guestEmail = "[email protected]";
var siteURL = "https://tenant.sharepoint.com/sites/abc";
var displayName = "";
Invitation guestInvitation = 
GraphUtility.InviteGuestUser(token.AccessToken, guestEmail, siteURL, "", displayName);                                        
var guestUserId = guestInvitation.InvitedUser.Id;
var graphUrl = "https://graph.microsoft.com/beta/users/" + guestUserId;
var body = "{\"hireDate\" : \"" + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ") + "\"}";
var response = GraphHttpClient.MakePatchRequestForString(graphUrl, JsonConvert.DeserializeObject(body), "application/json", token.AccessToken);

hireDate property should be set for the newly created guest user in Azure AD.

1

1 Answers

0
votes

To my knowledge there currently is no way to avoid this delay since it can sometimes take 30 minutes to an hour for the state to change.

Since Graph API currently cannot check for this, we can use the the Azure AD reporting API to check the this status. We can get the Update user event and check the UserState to see if it is invited to achieve the goal. For more details about the Azure AD reporting API, you can this link.

You can leave feedback for Azure to cut back on this delay here.