Reputation: 95
I have an Asp.Net website which uses Azure Active directory authorization (Using ADAL) and it returns basic attributes such as display name of an user. What I want is to GET custom attributes (For an e.g. employeeID) using the Microsoft Graph API (NOT Azure AD API)
Example Graph API query :
string graphRequest = string.Format(CultureInfo.InvariantCulture,
"{0}{1}/users?api-version={2}&$filter=startswith(userPrincipalName, '{3}')",
graphApiEndpoint,
tenant,
graphApiVersion,
"SearchText.Text");
Upvotes: 4
Views: 3697
Reputation: 33094
You're calling Microsoft Graph using the URI pattern from Azure Graph API. These are distinct APIs that have different calling patterns.
The correct URI should be:
https://graph.microsoft.com/v1.0/users?$filter=startsWith(userPrincipalName, 'string')
By default, /users
only returns a limited set of properties. From the documentation:
By default, only a limited set of properties are returned ( businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName ).
To return an alternative property set, you must specify the desired set of user properties using the OData
$select
query parameter. For example, to return displayName, givenName, and postalCode, you would use the add the following to your query$select=displayName,givenName,postalCode
Note: Certain properties cannot be returned within a user collection. The following properties are only supported when retrieving an single user: aboutMe, birthday, hireDate, interests, mySite, pastProjects, preferredName, responsibilities, schools, skills, mailboxSettings
In other words, if you need something other than the default properties, you need to explisitly request the property set you want.
Based on the above, you're example code should look something like this:
const string graphApiEndpoint = "https://graph.microsoft.com";
const string graphApiVersion = "v1.0";
const string userProperties = "id,userPrincipalName,displayName,jobTitle,mail,employeeId"
string graphRequest = string.Format(CultureInfo.InvariantCulture,
"{0}/{1}/users?$select={2}&$filter=startswith(userPrincipalName, '{3}')",
graphApiEndpoint,
graphApiVersion,
userProperties,
"SearchText.Text");
Upvotes: 5