SharePoint API OData order by createddatetime not working

2022-06-27T12:02:44.687+00:00

I can't seem to get the orderby createddatetime working with the OData api query.
This are the api requests I've been using:
https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/Items?$orderby=createdDateTime%20desc&$top=5
&
https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/Items?$orderby=createdDateTime%20desc

What we have now:
A simple newspage that get's all of the sharepoint news items. We have come to the point that we have too many items to fit into one api answer. We could use the odata next link to get the other items but we just need the last few since we have copies saved into our database. We have a timer that runs every day to put the new items into our database.

What we want:
We want to use the same timer but it just needs to get the newest 5-or-so items.

Is my api request wrong?

Microsoft 365 and Office | SharePoint | Development
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. Sheena-MSFT 1,736 Reputation points
    2022-06-27T14:40:20.577+00:00

    Hi @RubenvandenBrinkMployAssociates-7142 ,

    oData query parameter $orderby can be used on the expanded properties of fieldvalueset.

    PFB screenshot
    215443-qnas.png

    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".


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.