Filter files by date range in OneDrive - microsoft-graph-api

I would like to obtain the OneDrive content using Microsoft Graph filtered by date so that only files created between particular dates are obtained.
I have tried:
/v1.0/me/drive/items/{id}/children?filter=createdDateTime ge 2016-02-26T14:41:09Z
but get following response
"error": {
"code": "invalidRequest",
"message": "The request is malformed or incorrect.",
"innerError": {
"request-id": "c636022f-2fa9-4e41-b8fc-63be5fc5e681",
"date": "2017-04-07T10:05:46"
}
}
I have also tried:
/v1.0/me/drive/root/children?filter=name eq 'folderapr05'
and it works.
Does OneDrive support filter parameter for dates?

Filtering by dateTime isn't supported.
If you're attempting to do this for the purposes of syncing with OneDrive, you may want to take a look at delta. This method allows your app to track changes to a drive and its children over time.

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

Teams Export API not allowing me to filter by channel

I'm trying to use the Teams Export API to export a single Teams channel. I have my permissions set up properly; if I make a request to
https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages (without specifying a filter), I get the paginated results of all of the channel messages on my team. If I copy the sample datetime filters in that documentation, I also get a successful response with the appropriate results.
A successful response gives me a list of messages. Each one shows a channelIdentity field, which contains a channelId (fields removed for readability):
{
"value": [
{
"channelIdentity": {
"teamId": "{TEAM ID}",
"channelId": "{CHANNEL ID}"
},
},
]
}
What I want is to use this channelIdentity/channelId field as a filter on the results, so that I can export just the messages from a single channel.
If I run GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=channelIdentity/channelId eq '{CHANNEL ID}', I get an error:
{
"error": {
"code": "BadRequest",
"message": "The entity property 'channelIdentity/channelId' and operationKind 'Equal' is not allowed in $filter query.",
"innerError": {
"date": "2022-11-16T23:47:06",
"request-id": "...",
"client-request-id": "..."
}
}
}
This reads to me like I'm not allowed to use eq with this ID. If I try a 'starts with', I get a different error:
GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=startswith(channelIdentity/teamId, '{CHANNEL ID}')
{
"error": {
"code": "BadRequest",
"message": "Only binary operation expressions are allowed.",
"innerError": {
"date": "2022-11-17T00:11:26",
"request-id": "...",
"client-request-id": "..."
}
}
}
I'm unclear on what this is trying to say - either the ID starts with that phrase or it doesn't; it seems like a binary expression to me.
Is there some other approach I should use to get these results filtered by channel ID?
This API is designed to export everything from a team for backup/archival scenario. So, filtering by a specific channel is not supported now.
If you wish you may suggest this feature on Microsoft Feedback portal.
Any reason why you don't use List Channel Messages?
You can then make a GET call against this URL:
"https://graph.microsoft.com/v1.0/teams/{teamid}/channels/{channel id}/messages"
Note - as per that link you will need to Request access:
https://learn.microsoft.com/en-us/graph/teams-protected-apis
One other method, if you are using Graph Explorer, is add the signed-in user to the team as an owner, and it will let you test this method, you just won't be able to call via an App Registration until you do fill out that form.

"Unknown Error" in Microsoft Graph API Get Staff Availability in MS Bookings

When trying to make a request to the graph API endpoint for getting staff availability info on MS Bookings I keep receiving the below error which returns status code 500. I had followed the guide here and also decoded my access token and verified I had the right permissions.
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"date": "2022-07-25T08:21:46",
"request-id": "aa302590-9a6e-47a4-a5ac-51a12ef5e72e",
"client-request-id": "aa302590-9a6e-47a4-a5ac-51a12ef5e72e"
}
}
}
I also encountered the same error in graph explorer.
Well this seemed to work for me when I changed the timeZone value on the request payload from my local time zone to 'UTC'. So my request payload was changed as below
However same error persists on graph explorer - guessing its because application permissions are not currently supported on graph explorer

Filtering users by business phone number with MS Graph API fails

According to the MS Graph API documentation, businessPhones are supported to be used in a $filter query with eq comparison, just like the imAddresses property.
When inspecting Microsoft's use query parameters documentation, there's an example where the imAddresses property is used in a collection filter and it works just fine.
GET https://graph.microsoft.com/v1.0/users?$filter=imAddresses/any(s:s eq 'admin#contoso.com')
My goal ist to list all users that have a specific phone number in their businessPhones collection property.
However, when I try to use the businessPhones property in a similar query, the query does not work as expected.
GET https://graph.microsoft.com/v1.0/users?$filter=businessPhones/any(s:s eq '1234')
Status code: 400
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'businessPhones' of resource 'User'.",
"innerError": {
"date": "2021-07-30T08:07:24",
"request-id": "ac3923be-de11-448f-b2b5-245edc82d20e",
"client-request-id": "ac3923be-de11-448f-b2b5-245edc82d20e"
}
}
}
Any ideas on what I am missing?
You need to use advanced query capabilities, which means you need to add a $count=true query string parameter and a ConsistencyLevel=Eventual header to your request.

Microsoft Graph Excel API - request not working with multiple ranges

Can we access specific cell values from multiple ranges using a single Microsoft Graph request?
For example:
https://graph.microsoft.com/v1.0/me/drive/items/{file-id}/workbook/worksheets('{id}')/Range(address='e10:e11,c58:c59')
If I request only one range then I am getting the expected result. If I use the query above to get two specific ranges is not working:
"error": {
"code": "InvalidArgument",
"message": "The argument is invalid or missing or has an incorrect format.",
"innerError": {
"request-id": "1d3d0a3c-cf6f-4f0c-8e84-c65ff80cd020",
"date": "2017-07-25T14:13:11"
}
}
I suspect you're attempting to use Graph in the same way VBA can be used to refer to multiple ranges (i.e. Worksheets("Sheet1").Range("C5:D9,G9:H16,B14:D18")). This isn't model isn't supported by Graph.
Instead you'll need to pull each range using a separate GET request:
GET workbook/worksheets/Sheet1/range(address='e10:e11')
GET workbook/worksheets/Sheet1/range(address='c58:c59')

Resources