Creating unique mail ID (using graph api) if user with same name already exist

Ayan Usmani 171 Reputation points
2022-07-06T11:04:21.757+00:00

Let suppose I have user Rohan Joshi present in my AD and there is a new user with same name who joins us.

I wanted their details to be Rohan.Joshi@xyz .com & Rohan.Joshi1@xyz .com in my AD

How can we acheive it using the Graph '/user' API ?

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. Shivam Dhiman 6,086 Reputation points
    2022-07-06T11:53:58.74+00:00

    Hi @Ayan Usmani

    To create user with ******@xyz.com id you can use User Graph API. Here is the sample request for the same.

     Post https://graph.microsoft.com/v1.0/users  
            {  
          "accountEnabled": true,  
          "displayName": "Roshan Joshi01",  
          "mailNickname": "Roshan",  
          "userPrincipalName": "******@xyz.onmicrosoft.com",  
          "passwordProfile" : {  
            "forceChangePasswordNextSignIn": true,  
            "password": "Tree@1234"  
            }  
        }  
    

    As you can see using the above request I am able to create user in my test tenant.
    218100-azure4.png

    For more details please refer to this documentation.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ayan Usmani 171 Reputation points
    2022-07-06T14:58:11.75+00:00

    Thanks Shivam for the details !!!

    I am aware about this API but my query is how will we know before hand that user with name Rohan Joshi is already present and that we have to use some other variation of the same name as you showed.

    Is there any api to check if the user with same name exist and we get some suggested name to be used.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.