How to apply multiple filters at a same time in graph API against SPO document library metadata?

karthick A 25 Reputation points
2025-02-06T10:32:23.0066667+00:00

Hi, I am working with Microsoft Graph API to query a SharePoint document library. I need to apply multiple filters to the metadata fields like Department and AccountNumber.

However, I'm unsure of the correct syntax to use with the $filter query option for multiple conditions.

For example, I want to filter documents where (same time):

  • Department is 'Legal'
  • AccountNumber is '401'

I triedthe following query, but it did not return the expected results:

https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/items?$filter=fields/Department eq 'Legal' and fields/AccountNumber eq '401'

Can you please guide me on the correct syntax or approach to use multiple filters in this case?

Also give me an idea about how this can be done if incase i have all my documents spread accross multiple document libraries which are present under one site or multiple site under the same tenant.

Thanks!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,307 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,447 questions
{count} vote

Accepted answer
  1. RaytheonXie_MSFT 40,006 Reputation points Microsoft External Staff
    2025-02-10T05:56:04.5566667+00:00

    Hi @karthick A,

    I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    [How to apply multiple filters at a same time in graph API against SPO document library metadata?]

    Issue Symptom:

    Get SharePoint items using Graph Api with multiple filters doesn't return expected results.

    Solution:

    Indexing the columns used in the filter (Department & AccountNumber) fixed the issue.


    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!


2 additional answers

Sort by: Most helpful
  1. DBG 2,376 Reputation points
    2025-02-06T18:54:54.79+00:00

    Make sure you are using the "internal" names of your columns (fields).

    0 comments No comments

  2. RaytheonXie_MSFT 40,006 Reputation points Microsoft External Staff
    2025-02-07T03:06:35.5333333+00:00

    Hi @karthick A,

    Per my test, if you are using choice column for Department and number column for AccountNumber. Your graph api will run successful.

    User's image

    And sometimes Department column might be lookup column. This is not supported for drive item, you should do the filter for listitems:

    https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items?$expand=fields&$filter=fields/DepartmentLookupId eq 1 and fields/AccountNumber eq '401'
    

    If the lookup field contains multiple values, you could select all the items and then perform filter

    https://graph.microsoft.com/v1.0/sites/(site-id)/lists/(list-id)/items?$expand=fields&$filter=(fields/LookupDepartment/any(x:x/LookupValue eq 'Legal') and fields/AccountNumber eq '401')
    

    Here is a similar issue with yours, please make a reference

    https://stackoverflow.com/questions/61498974/filter-multiple-lookup-field-with-microsoft-graph


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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.