$filter Azure Audit logs - azure

I am using the following API
https://learn.microsoft.com/en-us/graph/api/directoryaudit-list?view=graph-rest-1.0&tabs=http
I want to filter resources for only UserManagement category but for some reason the API call I am making gives me error
This is the exact API call
GET https://graph.microsoft.com/v1.0/auditLogs/directoryAudits?$filter=category/any(s:s eq 'UserManagement')
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2021-08-10T06:27:37",
"request-id": "cfd471b2-8b13-4a43-b3de-c6a963425f8c",
"client-request-id": "cfd471b2-8b13-4a43-b3de-c6a963425f8c"
}
}
}

I was able to filter data using startsWith instead of ne
https://graph.microsoft.com/v1.0/auditLogs/signIns?$filter=startsWith(userPrincipalName, 'user.com#EXT##dm4.onmicrosoft.com')

Apparently the lambda operator doesn't work but I can still query like this
https://graph.microsoft.com/v1.0/auditLogs/directoryAudits?$filter=category eq 'UserManagement'

Related

MS Graph API - List Children in DriveItems is failing with 404(itemNotFound)

I'm using the API v1.0/sites/:id/drive/items/:parent/children to fetch the children informations of the drive item. I'm able get the response for some sites but for couple of sites I end up with the error 404(itemNotFound).
I passed siteId in place of :id & parentReferenceId in place of :parent.
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"date": "2022-03-15T05:25:34",
"request-id": "2afc519e-95b0-45b0-bd91-3c716154cdcd",
"client-request-id": "2afc519e-95b0-45b0-bd91-3c716154cdcd"
}
}
}
What is the reason for this behavior?
Try this url pattern to get list of files and sub-folders
https://graph.microsoft.com/v1.0/sites/<SITE_ID>/drives/<DRIVE_ID>/root:<PATH_TO_NESTED_SUB_FOLDERS>:/children
Example:
https://graph.microsoft.com/v1.0/sites/9e9145345-7f9j-4695-8701-bae4c2d8a553/drives/b!HTaRnpV7lUaKdgmdflilU5eQE4tMetVNifXIJN28qvp68vQzkrpfTLPMl6eBQi_4/root:/InnerFolder/InnerFol2:/children

Microsoft Graph API Add "Error while adding group as a member to other group"

I am getting an error when adding a group as a member of other group using the Microsoft Graph API. It was working okay before, but now it's giving me an error.
I am using this:
POST https://graph.microsoft.com/v1.0/groups/{group-id}/members/$ref
Content-type: application/json
body:
{
"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
}
And I am getting this error:
{
"error": {
"code": "Request_BadRequest",
"message": "An invalid operation was included in the following modified references: 'members'.",
"innerError": {
"date": "2021-09-08T16:09:31",
"request-id": "b1f3a1d9-96ae-4f3e-9ec0-73781bed4379",
"client-request-id": "b1f3a1d9-96ae-4f3e-9ec0-73781bed4379"
}
}
}

Graph REST API - Cannot access a DriveItem's ListItem

I'm using the rest api to access my drive's items.
I can access the items perfectly fine like this:
https://graph.microsoft.com/v1.0/drives/{{driveid}}/items/{{folderid}}/children
But this is where my problems lie:
This:
https://graph.microsoft.com/v1.0/drives/{{driveid}}/items/{{folderid}}/children?expand=fields
Gives this result:
{
"error": {
"code": "invalidRequest",
"message": "Could not find a property named 'fields' on type 'oneDrive.item'.",
"innerError": {
"date": "2021-09-02T10:50:12",
"request-id": "075bf9b7-c93a-43d2-a1ed-bd4563399f1a",
"client-request-id": "075bf9b7-c93a-43d2-a1ed-bd4563399f1a"
}
}
}
And this:
https://graph.microsoft.com/v1.0/drives/{{driveid}}/items/{{folderid}}/children?expand=listitem
Gives this result:
{
"error": {
"code": "invalidRequest",
"message": "Could not find a property named 'listitem' on type 'oneDrive.item'.",
"innerError": {
"date": "2021-09-02T10:50:30",
"request-id": "2db87d5f-fbe9-42ad-a61e-a377bafafcad",
"client-request-id": "2db87d5f-fbe9-42ad-a61e-a377bafafcad"
}
}
}
I've tried ?$expand=fields and that gives me this message:
"Parsing OData Select and Expand failed: Could not find a property named 'fields' on type 'microsoft.graph.driveItem'."
What am I doing wrong? Because I have another separate SharePoint site and the ?expand=listitem works perfectly.
I've managed to get a decent workaround by using the Graph SDK:
graphClient
.Sites[SiteID]
.Drives[DriveID]
.Items[FolderID]
.Children
.Request()
.Expand(item => item.ListItem)
.GetAsync();

Microsoft Graph(German cloud) - Get root site (sites/root)

When making a call to the Microsoft German Graph /sites/root endpoint, it returns 'Resource Not Found', although that in global Graph the same endpoint works perfectly ok
Here is an example:
https://graph.microsoft.de/v1.0/sites/root
It returns:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'sites'.",
"innerError": {
"request-id": "aff4a613-54ed-476d-976f-d4ac7a8c7ee2",
"date": "2018-04-26T07:59:17"
}
}
}
Found an answer, for now, this service is deployed only in the "beta" API
So I used https://graph.microsoft.de/beta/sites/root and it works

Azure Graph API Nested Group Membership

I need to query a user's nested group membership. memberOf only give direct group membership. When I try getMemberGroups, getMemberObjects, checkMemberGroups, etc. using version 1.5 or 1.6, I'm getting this:
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "Method Not Allowed"
}
}
}
Any ideas on how to fix this?
You might be making a GET request. According to documentation, you need to make a POST request for getMemberGroups.
URL:
https://graph.windows.net/domain.com/users/first.last#domain.com/getMemberGroups?api-version=1.6
Request body:
{
"securityEnabledOnly": true
}
Here the parameter defines if you want only security groups back, or if it should return Office 365 groups too.

Resources