Forum Discussion
yasi67
Dec 29, 2022Copper Contributor
searching an External user in People picker and starting an invitation
I want to write code to search for non-existing external user email for next step giving me this email as suggestion for sending them an invitation. for example, there is a functionality by Standard...
SvenSieverding
Dec 29, 2022Bronze Contributor
Hi,
i think they are just checking if the email address entered matches a given pattern and if the domain is not yours. They are not actually searching for the address. (As you can enter every mail adress even if it does not exist)
You can code this in javascript like this:
const address="email address removed for privacy reasons"
if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(address)) {
console.log(`${address} is a valid mail address`)
}
Then you can use the "Invivations" Endpoint of Microsoft Graph to send the actual invitation
https://learn.microsoft.com/en-us/graph/api/invitation-post?view=graph-rest-1.0&tabs=http
POST https://graph.microsoft.com/v1.0/invitations
Content-type: application/json
{
"invitedUserEmailAddress": "email address removed for privacy reasons",
"inviteRedirectUrl": "https://myapp.contoso.com"
}
Best Regards,
Sven