Francisco Imperio
Francisco Imperio

Reputation: 1

Using Managed EWS API ResolveName to get contact's Azure object ID

I am successfully using ResolveName to get most of the contact information I need. Below is the code I am using:

PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties); NameResolutionCollection match = await mailClient.Service.ResolveName(customerEmail, ResolveNameSearchLocation.DirectoryOnly, true, itempropertyset);

I am querying against my Office365/Azure AD tenant. One of the values I need is not being returned though.

I would like to get the user/contact's Object ID as shown in the Azure Portal - Azure Active Directory - Users - Basic Info screen.

Is that possible using EWS Managed API?

Regards.

Upvotes: 0

Views: 150

Answers (1)

Sridevi
Sridevi

Reputation: 22222

You cannot get Azure AD user's object ID using EWS Managed API. Alternatively, you can make use of Microsoft Graph API.

I tried to reproduce the same in my environment via Graph Explorer and got below results:

I have Azure AD user named Sri in my tenant with below properties:

enter image description here

To get the Azure AD user's details via Graph API, I ran below query:

GET https://graph.microsoft.com/v1.0/users/user_principal_name

Response:

enter image description here

To get only object ID of an Azure AD user, you can include $select in the query like below:

GET https://graph.microsoft.com/v1.0/users/user_principal_name?$select=id

Response:

enter image description here

Before running the above queries, make sure to grant consent to required permissions like below:

Go to Graph Explorer -> Modify permissions -> Click on Consent

enter image description here

You will get consent screen and click on Accept like below:

enter image description here

After granting the consent, you can run the queries successfully.

Upvotes: 0

Related Questions