Selvarathinam Vinoch
Selvarathinam Vinoch

Reputation: 1100

Provide the 'allowthrottleablequeries' preference to allow this

I have developed an API using Microsoft Graph API. I am encountering below issue.

URL that I am calling :

/v1.0/sites/root/lists/cb32cc85-5351-423d-b2ec-bb418c1d9c64/items?
$filter=fields/Created gt '2018-1-1T00:00:00'
&expand=fields
&$orderby=createdDateTime
&$top=10

Error returned from the API :

Field 'Created' cannot be referenced in filter or orderby as it is not indexed. Provide the 'allowthrottleablequeries' preference to allow this, but be warned that such queries may fail on large lists.

How to enable allowthrottleablequeries as it says and how should I achieve this?

Upvotes: 2

Views: 1385

Answers (3)

Ben Oates
Ben Oates

Reputation: 1

In the Java SDK you can add the headers to the request by adding a header to the .get(GetRequestConfiguration) part of the graph call.

Here is a sample getting all the pdf files in a site that has examples of setting a header, filtering, and expanding.

    private final String siteIdProductDevelopment = "your site ID";
    private final String sharedDocumentsListId = "you list id";
    
    var result = graphServiceClient.sites()
        .bySiteId(siteIdProductDevelopment)
        .lists()
        .byListId(sharedDocumentsListId)
        .items()    
            .get(request ->
  request.headers.add("Prefer",HonorNonIndexedQueriesWarningMayFailRandomly");
    request.queryParameters.expand = new String []{"fields"};
    request.queryParameters.filter = "fields/ContentType eq 'Document' and fields/DocIcon eq 'pdf'";
                    })
            .getValue();

Upvotes: 0

Namwar Rizvi
Namwar Rizvi

Reputation: 143

Try to send your request with following Request Header

Prefer: allowthrottleablequeries

If it does not work then try the following Request Header

Prefer: HonorNonIndexedQueriesWarningMayFailRandomly

Upvotes: 0

Marc LaFleur
Marc LaFleur

Reputation: 33094

I'm afraid this isn't a very clear or useful error message. As far as I know, there isn't actually a way to enable allowthrottleablequeries.

This happens when a SharePoint list grows too large to handle filtering or sorting non-indexed columns. The fix is to add an index to the created column in your List Settings. You can find instructions on how to accomplish this in Add an index to a SharePoint column.

Upvotes: 1

Related Questions