Error when using orderby

Rizwan Ansari 91 Reputation points

Dear Experts,

I am calling sharepoint rest api using graph,{site-id}/lists/{list-id}/items?expand=fields(select=Title)&$orderby=fields/SortOrder

Added the column to index also added

'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly'

in header.

but getting error in response:

    "error": {
        "code": "invalidRequest",
        "message": "Field 'SortOrder' 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.",
        "innerError": {
            "date": "2023-09-04T07:34:20",
            "request-id": "32b25e8a-38c8-45b4-a377-f95c39e0dd87",
            "client-request-id": "32b25e8a-38c8-45b4-a377-f95c39e0dd87"

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
2,088 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
8,072 questions
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 24,201 Reputation points Microsoft Vendor

    Hi @Rizwan Ansari @Iginio Colangelo,

    Per your descriptions, there might be some issues in the backend of Graph api. As a workaround, I will suggest you to raise a support in Microsoft Azure. You can report this bug to Microsoft and get a response within one business day usually.

    1 person found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. Garcia Argüez, Javier 15 Reputation points

    I have the same problem, the app has stop working this weekend. I have tried in MS Graph with different lists and documents libraries and have the same error. And the fields are indexed a long time ago.

    1 person found this answer helpful.

  2. Bayraktar, Aytac 5 Reputation points

    User's image

    1 person found this answer helpful.
    0 comments No comments

  3. RaytheonXie_MSFT 24,201 Reputation points Microsoft Vendor

    Hi @Rizwan Ansari,

    Per my test, query parameter $orderby can be applied on the expanded properties of fieldvalueset, and usage of the is not recommended large lists. Please refer to following{site-id}/lists/{list-id}/items?$expand=fields&$orderby=fields/SortOrder desc 
    Prefer: HonorNonIndexedQueriesWarningMayFailRandomly

    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.

  4. Chetan Kolhari 0 Reputation points

    I have customer complains about having the same issue in their tenants from yesterday. So far any progress from Microsoft anyone heard?