MS Graph API sites filter not working

Thai Pham 21 Reputation points
2022-08-15T01:49:35.96+00:00

I'm trying to filter a site with the display name "EEU User - UAT" using the Python library https://github.com/microsoftgraph/msgraph-sdk-python-core

The query that was sent to the Graph API looks like
https://graph.microsoft.com/v1.0/sites?%24filter=contains%2528displayName%252C%2527EEU%2520User%2520-%2520UAT%2527%2529

I'm not sure what's wrong with it but it returned "Invalid filter clause".

Microsoft 365 and Office SharePoint For business Windows
Microsoft Security Microsoft Graph
{count} votes

Accepted answer
  1. Srinivasa Rao Darna 6,761 Reputation points Microsoft External Staff
    2022-08-15T13:40:49.767+00:00

    Hi @Thai Pham ,

    Your Graph API query should be GET /sites?$filter=contains(displayName,'EEU User - UAT') and you can only use this with application permissions.

    You must be getting this error "Cannot enumerate sites" when using delegated permissions.
    Currently List all site collections is supported with application permissions only.

    231133-list-sites.png

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Joe Blow 25 Reputation points
    2023-08-29T20:08:24.1966667+00:00

    First, the docs for this API are horrible.

    I was receiving the same "cannot enumerate sites" error when using valid filter queries. The fix was to stop using the https://graph.microsoft.com/v1.0/sites/ endpoint and use https://graph.microsoft.com/v1.0/sites/getAllSites instead. My filters started working after using getAllSites.

    Cheers.

    5 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.