'Exception while processing email invitation : The invited user already exists in the directory
I have the below code written in c#, and using Micorosoft Graph API
//Get redemption URL
var invitation = new Invitation
{
InvitedUserEmailAddress = "<email address>",
InviteRedirectUrl = "<Redirect URL>",
SendInvitationMessage = false,
};
var inviteResponse = graphClient.Invitations
.Request()
.AddAsync(invitation).Result;
I see following error in the log
ProcessEmailInvitation - Exception while processing email invitation: One or more errors occurred. (Code: BadRequest Message: The invited user already exists in the directory as object ID: xxxxx-xxxxxx-xxxxxxxxx-xxxxxxxxx.
Is it anything to do with SendInvitationMessage parameter?
I tried to change the code as follow,
var inviteResponse = Task.Run(async () => await graphClient.Invitations.Request().AddAsync(invitation).Result);
but it says
Microsoft.Graph.Invition is not awaitable.
Solution 1:[1]
The error indicated that you may invite a user who is already be invited into your tenant, you may test with another email account. And pls allow me to post a sample code here for a better look. If it doesn't help you I'll delete it. By the way SendInvitationMessage is false by default according to the api document.
public async Task<string> inviteUserAsync() {
var invitation = new Invitation
{
InvitedUserEmailAddress = "[email protected]",
InviteRedirectUrl = "https://www.google.com"
};
await _graphServiceClient.Invitations.Request().AddAsync(invitation);
return "success";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tiny Wang |
