Can't $filter SharePoint list items by Id with Graph

Michael Weinhardt 10 Reputation points
2024-12-15T01:56:03.2+00:00

Hi,

I want to do this:

https://graph.microsoft.com/v1.0/sites/8aaxxxxxxxxxxx8e1/lists/1a3xxxxxxxxxcc6/items?$filter=(fields/id eq '1' or fields/id eq '2')

I get the following when I try it (via Graph Explorer):

{
    "error": {
        "code": "invalidRequest",
        "message": "A provided field name is not recognized",
        "innerError": {
            "date": "2024-12-14T22:01:49",
            "request-id": "3f50e6fa-c5f5-45ab-b6fb-e2182e4e0eda",
            "client-request-id": "51fc0580-de09-2a7a-626c-e733bad58f8e"
        }
    }
}

This error message is pretty vague - I have no idea which field name is not recognized and, more importantly. why it is?

How can I use Graph to return a set of list items filtered by list item Id?

I do not want to use the, what must be soon to be replaced?, SharePoint REST API ie versus Graph.

I am trying to avoid the Apply to Each (ID) -> Get SharePoint Item loop by instead making one call to get just the items I want with just the fields I want selected and then iterate over that without having to make any further calls ie by getting list items one at a time.

Also, I have this working with the SharePoint connector of course, but I am aiming to create a domain-specific custom connector with Graph.

Thanks!
Michael

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

1 answer

Sort by: Most helpful
  1. Saranya Madhu-MSFT 2,375 Reputation points Microsoft External Staff
    2024-12-16T03:33:45.7766667+00:00

    Hi @michael weinhardt ,

    Thanks for reaching out to Microsoft!

    As per documentation, to enumerate items in a list, you can use the following endpoints:

    GET /sites/{site-id}/lists/{list-id}/items: This endpoint retrieves all items in the specified list.

    GET /sites/{site-id}/lists/{list-id}/items?expand=fields: This endpoint retrieves all items in the specified list and expands the fields to include additional details.

    GET /sites/{site-id}/lists/{list-id}/items?expand=fields(select=Column1,Column2): This endpoint retrieves all items in the specified list and expands the fields to include only the specified columns (Column1 and Column2 in this example).

    However, please note that according to the documentation, the optional query parameter to filter based on item ID is not supported for these endpoints.

    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.

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.