Fields return null in Graph API Query - microsoft-graph-api

Querying the graph API returns null for many fields which should not be null, for example jobTitle, userType, createdDateTime, and isAccountEnabled. Why are these fields showing up as null? Is there something that needs to be enabled from the global Azure AD?
How can I get these fields to return with their proper values rather than null?

You need the permission "Directory.Read.All" at least.
So that you can read user data in your organization's directory. Otherwise, you will get "null" value.
Microsoft Graph permissions reference - Directory permissions

Related

Can't retrieve outlook add-in custom properties from graph API

I need to save a custom property from my outlook add-in and retrieve the this value from graph Api.
I followed MS documentation, this link and this one.
I store the custom property with office.js methods loadCustomPropertiesAsync and customProps.saveAsync
I have checked the value is correctly stored to custom properties (I can read it from add-in when I come back to event)
When I try to check the value from graph API, the event is returned without custom props.
here is the request I use :
{{endpoint}}/Users/bc2d0290-xxx-4041d2d39b66/Events/AAMkADI1YTJjZTI1LWM4YjUtNxxxTvAAA=?$expand=singleValueExtendedProperties($filter=id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-myAddInManifestId')
What am I doing wrong ?
I found my mistake.
I use custom properties to enrich appointements with conference room.
I tried to retrieve custom props on my server from room eventId instead of organizer eventId

Bug: createdDateTime is null in /beta/users

When calling the Microsoft Graph API to get a specific user, the createdDateTime field is returned without any data.
https://graph.microsoft.com/beta/users/user#domain.com
However, when searching for the user, the field is returned correctly.
https://graph.microsoft.com/beta/users?$filter=startsWith(userPrincipalName, 'user#domain.com')
The bug can be reproduced using the GraphExlorer web-site: https://developer.microsoft.com/en-us/graph/graph-explorer
I'm not sure where to report this, so I posted it here.
I think I might have found the answer.
When I do a GET operation using the Azure AD 'id' the createdDateTime is populated. When I retrieve the same user using the userPrincipalName, the createdDateTime value is returned as null. I suppose the issue is that the value is retrievable by the back-end query when the Azure AD 'id' property is used while the userPrincipalName (which is a mutable/changeable property) is not. Bizarre but at least there seems to be an answer. Hope this helps.

Select=*,PropertyName does not return the value for the PropertyName in Microsoft Graph api

In Graph Explorer if i make a request to:
/v1.0/users/[User.Id]/drive/root/children?$select=*,sharepointIds
I do not get back the sharepointIds property from MS Graph.
If I remove * from select query parameter and only request sharepointIds property then I get the sharepointIds property and its values.
v1.0/users/[User.Id]/drive/root/children?$select=sharepointIds
I would expect $select=*,sharepointIds to return both the default properties and the sharepointIds in the same response.
Is there another working way for the clients to request additional properties from Microsoft Graph without typing all of the property names in the object one by one including the default properties?
The underlying OneDrive API seems to handle select=*,[propertyName] correctly.
This isn't possible today. Microsoft Graph currently doesn't support wildcards in a $select query parameter. Each property you want to return must be explicitly listed in the $select.

How to query/filter from Microsoft Graph all groups where a user is owner

I would like to query from Microsoft Graph all groups where a specific user is owner.
I tried the following query:
https://graph.microsoft.com/v1.0/groups?$filter=owners/any(owner: owner/id eq '4dc60fe7-8009-4131-a4e9-80dc5e86f98f')
Unfortunately this returns a 400.
Does anyone know the correct OData query? Or is this not even supported by MS Graph?
It's not possible to filter on owners. The documentation states which properties can be $filter'ed.
Look for
Supports $filter
in the description of each property.
You are going to have to read all groups, pull out their owners, and do the filtering client side.
The memberOf endpoint returns all the groups of a given user:
https://graph.microsoft.com/v1.0/users/{ID or email}/memberOf
Will return:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
"value": [
{
"id": "XXXX-XXXX-XXXX-XXXX",
"displayName": "The group name",
"...":"...",
}
]
}
It is possible to get all groups with owners using single API call like this:
https://graph.microsoft.com/v1.0/groups?$expand=owners
and then select groups which have current user in owners collection.
You could use List ownedObjects graph API to do that where it gets the list of directory objects that are owned by the user.
But as the question is specifically about getting the list of groups that a user is owner of, you can use the below graph API where it gets the list of directory objects with odata.type as microsoft.graph.group:
GET https://graph.microsoft.com/beta/users/{User Object ID}/ownedObjects/microsoft.graph.group
And if you just want to get the group name and group ID, you can use $select,
GET https://graph.microsoft.com/beta/users/{User Object ID}/ownedObjects/microsoft.graph.group?$select=displayName,id

Unable to expand MemberOf using Microsoft Graph .NET SDK using Delta Query

Expanding properties doesn't seem to work when using Delta queries. It works fine with regular user query.
Is this a limitation in Microsoft Graph API?
var usersInfo = graphServiceClientWithApplicationPermission.Users.Delta().Request().Expand("MemberOf").GetAsync();
// Add inital request users
foreach (var userInfo in usersInfo)
{
// Member info doesn't seem to be expanded even if $expand=MemberOf is sent
if (userInfo.MemberOf == null)
{
userInfo.MemberOf = await applicationPermissionsClient.Users[userInfo.Id].MemberOf.Request().GetAsync();
}
// MemberOf is now populated ??
}
Seems like this is another limitation of the Microsoft Graph and not supported.
Optional query parameters
If a client uses a query parameter, it must be specified in the
initial request. Microsoft Graph automatically encodes the specified
parameter into the nextLink or deltaLink provided in the response. The
calling application only needs to specify their desired query
parameters once upfront. Microsoft Graph adds the specified parameters
automatically for all subsequent requests. For users and groups, t
here are restrictions on using some query parameters:
If a $select query parameter is used, the parameter indicates that the
client prefers to only track changes on the properties or
relationships specified in the $select statement. If a change occurs
to a property that is not selected, the resource for which that
property changed does not appear in the delta response after a
subsequent request. $expand is not supported.
For users and groups beta (preview) APIs, scoping filters allow you to
track changes to one or more specific users or groups by objectId. For
example, the following request:
https://graph.microsoft.com/beta/groups/delta/?$filter= id eq
'477e9fc6-5de7-4406-bb2a-7e5c83c9ae5f' or id eq
'004d6a07-fe70-4b92-add5-e6e37b8acd8e' returns changes for the groups
matching the ids specified in the query filter.
https://developer.microsoft.com/en-us/graph/docs/concepts/delta_query_overview

Resources