Microsoft Graph API - not able to use orderby or filter on createdDateTime for Sites

594 Views Asked by At

I want to query Sites using Microsoft Graph API that were created after a certain time. So I created the following filter query:

createdDateTime ge 2023-01-01T00:00:00Z

I also tried:

createdDateTime ge `2023-01-01T00:00:00Z`

Both generated an invalid request error with no details.

I then tried just doing an orderby createdDateTime. This did "work" but it sorted each page, not the whole dataset. So page 2 had items that should have been in page 1 and so on.

Microsoft Graph API seems really crappy. Does anybody know how to achieve this? Any help would be greatly appreciated.

1

There are 1 best solutions below

0
user2250152 On

I've never found a way how to use filter on /sites endpoint.

I'm using /search/query endpoint for searching SharePoint sites based on some criterion.

You should be able to specify filter by Created and properties for sorting.

POST https://graph.microsoft.com/v1.0/search/query

{
    "requests": [
        {
            "entityTypes": [
                "site"
            ],
            "query": {
                "queryString": "Created > 2022-01-01 AND Created < 2022-12-31"
            },
            "from": 0,
            "size": 25,
            "sortProperties": [
                {
                    "name": "Created",
                    "isDescending": "false"
                }
            ]
        }
    ]
}