office365 Graph API to list only admin users - microsoft-graph-api

I am trting to get all admin users from Office365 using Graph Users API. But userType of Admin users is null. Due to this I am not able to apply filter userType eq null. Is there any option to get only Admin users?
https://graph.microsoft.com/v1.0/users?$filter=userType eq null
error response:
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'userType' of resource 'User'.",
"innerError": {
"date": "2020-07-01T17:14:04",
"request-id": "resource-id"
}
}
}

You need to use the unifiedRoleAssignments Api to list all the members of the Global/Company administrator role

Related

How to filter users in microsoft graph list?

I am using https://graph.microsoft.com/v1.0/users
endpoint from the Microsoft Graph API to get the users from the organisation. it is giving me a list of all the users but I want just users, those are created after 01-01-2023.
I have tried using above endpoint with https://graph.microsoft.com/v1.0/users?$filter=create/dateTime ge '2023-01-01T00:00' but it is giving me below error.
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Property 'dateTime' does not exist as a declared property or extension property.",
"innerError": {
"date": "2023-01-17T08:19:15",
"request-id": "3129e8a3-0f00-4e14-99fc-2741f50d12d1",
"client-request-id": "28ecaa31-31dd-3c00-7d7c-474173eb1512"
}
}
}
I don't know how to filter in the above endpoint with time. If you could help?
The correct property name is createdDateTime. Do not use quotes around date and time in this case.
https://graph.microsoft.com/v1.0/users?$filter=createdDateTime ge 2023-01-01T00:00:00Z
To filter between two dates:
https://graph.microsoft.com/v1.0/users?$filter=createdDateTime ge 2023-01-01T00:00:00Z and createdDateTime le 2023-01-07T00:00:00Z

How to $filter appRoleAssignments based on appRoleId?

I have an enterprise application registered in Azure AD Tenant. It contains certain appRoles which have been assigned to Azure AD Users. Now, I would like to fetch all the users having some specific appRoles.
I have tried this:
GET /servicePrincipals/{id}/appRoleAssignedTo
taken from here:https://learn.microsoft.com/en-us/graph/api/serviceprincipal-list-approleassignedto?view=graph-rest-beta&tabs=http#optional-query-parameters
It seems like I am able to fetch all the appRoleAssignments successfully using this API, but whenever I put a filter such as: appRoleId eq {app-role-id} I am geting error like:
{
"error": {
"code": "Request_BadRequest",
"message": "Invalid filter clause appRoleId: System.Guid",
"innerError": {
"date": "2021-10-25T16:33:41",
"request-id": "{request-id}",
"client-request-id": "{client-request-id}"
}
}
}
And whenever I put single quotes, like appRoleId eq '{app-role-id}', I get this error:
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2021-10-25T16:34:30",
"request-id": "{request-id}",
"client-request-id": "{client-request-id}"
}
}
}
I tried with both v1 and beta endpoint. So how do I filter on appRoleId?
It seems that Microsoft Graph does not support the $filter on appRoleId yet. They already have an open issue:
https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/990
There is also a feature request here which we can upvote: https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/application-api-add-support-for-filtering-approleassignment-by/idi-p/2433822
Also in the Doc, $filter is only provided on principalDisplayName and resourceId
[1]: https://i.stack.imgur.com/ZVD8Y.png

Function-specified Filter clause doesn't work for getting Sharepoint item list in Graph API

I'm trying to get a list of SharePoint items using Graph API with a Filter clause, but I get an error when I specify a function such as StartsWith.
The following page says, "Support for the $filter operator varies depending on the Microsoft Graph API. Commonly supported are the following logical operators." Is it possible to use them?
https://learn.microsoft.com/en-us/graph/query-parameters#filter-parameter
■In the case of eq, data can be retrieved
/sites/{site-id}/lists/{list-id}/items?$expand=fields&$filter=fields/Title eq 'test'
■In the case of startsWith, an error will occur saying it is an invalid filter clause.
/sites/{site-id}/lists/{list-id}/items?$expand=fields&$filter=fields/Title startsWith 'test'
ErrorMessage :
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2021-07-13T02:09:30",
"request-id": "5f84935b-59f1-46cf-a160-18d64e989eb7",
"client-request-id": "e417c442-123d-ba3b-1465-8ff7f4f78645"
}
}
}
You should specify startswith in your Graph API URL as :
$filter=startswith(fields/Title,'test')

MS Teams: can not fetch channel messages with Graph API using an application token

I have created a test application which is requesting adminconsent from a MS teams admin with the following scopes :
openid offline_access channelmessage.read.group channelmessage.read.all chat.read chat.readbasic chat.readwrite user.read.all channel.readbasic.all directory.read.all group.read.all groupmember.read.all organization.read.all people.read.all presence.read.all team.readbasic.all
I am using an application token to fetch ms teams organization data like users, channels, teams etc. I have managed to fetch with Graph API the user, channel, teams data of an organization,
but when I tried to fetch messages
with
https://graph.microsoft.com/v1.0/teams/team_id/channels/channel_id/messages
I am getting the following error:
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"date": "2021-03-03T22:23:47",
"request-id": "a279044a-ab9e-4c18-af71-5a65ea7cee86",
"client-request-id": "a279044a-ab9e-4c18-af71-5a65ea7cee86"
}
}
}
When you are using application permissions you need to you must request access.For details, see Protected APIs in Microsoft Teams.

Filtering azure groups by createdDateTime using graph API

I am using the Microsoft Graph API. I was wondering whether or not filtering was supported on the createdDateTime property for the API groups:
https://graph.microsoft.com/v1.0/groups?$filter=CreatedDateTime ge '2019-01-01T21:15:12Z'
Error Message:
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"request-id": "xxxx",
"date": "2019-10-16T15:10:08"
}
}
}
10/18/2019
I have confirmed with Azure support engineer that filter is not supported on the createdDateTime property for the API groups.

Resources