1

We have a SharePoint list of items where we would like to filter on a specific field (i.e. EMail = [email protected]) to create a list of entries. We are getting 400 errors saying invalid filter expression.

This is our list schema:

enter image description here

Query, where we are selecting columns FirstName (PRD First Name), Title (PRD Last Name), BRK Name (BRK_x0020_Name), and Email (E-Mail), and then filtering to where the Email equals [email protected]:

public ListItemCollectionPage getRecipients(){
        LinkedList<Option> requestOptions = new LinkedList<>();

        requestOptions.add(new QueryOption("expand", "fields(select=FirstName,Title,BRK_x0020_Name,EMail)"));
        requestOptions.add(new QueryOption("$filter", "eq(EMail,'[email protected]')"));

        ListItemCollectionRequest listRequest = graphServiceClient.sites(graphConfig.getSiteId()).lists(graphConfig.getListId()).items()
            .buildRequest(requestOptions);
        
        System.out.println(listRequest.getRequestUrl());

        return listRequest.get();
}

The URL generated is:

https://graph.microsoft.com/v1.0/sites/{side-id}/lists/{list-id}/items?expand=fields%28select%3DFirstName%2CTitle%2CBRK_x0020_Name%2CEMail%29&%24filter=eq%28EMail%2C%27sample%40microsoft.com%27%29

Stack trace:

com.microsoft.graph.http.GraphServiceException: Error code: BadRequest
Error message: Invalid filter clause

400 : Bad Request
[...]

 

[Some information was truncated for brevity, enable debug logging for more details]
    at com.microsoft.graph.http.GraphServiceException.createFromResponse(GraphServiceException.java:419) ~[microsoft-graph-core-2.0.14.jar:na]
    at com.microsoft.graph.http.GraphServiceException.createFromResponse(GraphServiceException.java:378) ~[microsoft-graph-core-2.0.14.jar:na]
    at com.microsoft.graph.http.CoreHttpProvider.handleErrorResponse(CoreHttpProvider.java:512) ~[microsoft-graph-core-2.0.14.jar:na]

What exactly is invalid about this request?

1 Answer 1

2

Try changing your filter to:

requestOptions.add(new QueryOption("filter", "fields/EMail eq '[email protected]'"));

You may get an error similar to,

"Field 'Email' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists."

If you get this error, you need to add a header to the request with the key of Prefer and the value of HonorNonIndexedQueriesWarningMayFailRandomly.

I looked but I was unable to find any official documentation from Microsoft on the use of this header.

1
  • I had a similar problem. This has worked for me! Commented Jan 13, 2023 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.