Microsoft Graph sharepoint lists API $orderby not working

Britney Tu 1 Reputation point
2022-04-21T19:16:26.99+00:00

I tried the following for sharepoint list items. It returns with a 200 response but not sorted properly by last modified datetime. Does microsoft currently support oDATA parameter $orderby for sharepoint list?

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$orderby=lastModifiedDateTime

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,227 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,741 Reputation points Microsoft Vendor
    2022-04-23T06:27:00.383+00:00

    Hi @Britney Tu ,

    Query parameter $orderby can be applied on the expanded properties of fieldvalueset, and usage of the is not recommended large lists.

    Following is an example snippet:

    /sites/{site-id}/lists/{list-id}/items?$expand=fields&$orderby=fields/Modified desc  
    Prefer: HonorNonIndexedQueriesWarningMayFailRandomly  
    

    Note: Please note that Prefer: HonorNonIndexedQueriesWarningMayFailRandomly should be added in the Request headers, but be warned that such queries may fail on large lists.

    Hope this helps.

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

    1 person found this answer helpful.
    0 comments No comments

  2. CarlZhao-MSFT 42,211 Reputation points
    2022-04-22T02:23:51.767+00:00

    Hi @Britney Tu

    Please see this document: Sorting collections:

    Note that in OneDrive for Business and SharePoint Server 2016, the orderby query string only works with name and url.

    Sharepoint online is actually OneDrive for Business.

    So filtering by lastModifiedDateTime is not supported in this case. It is supported for OneDrive Personal.


    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.