6

I want to fetch ID and Title of last created item from SharePoint list using REST. I am using below url but it gives me wrong item, there are more than 10k items in the list.

http://servmachine.contoso.com/_vti_bin/ListData.svc/Products?OrderBy=ID%20DSC&$top=1

1 Answer 1

9

For applying orderby and top you need to call it like this

http://servmachine.contoso.com/_vti_bin/ListData.svc/Products()?$top=1&$orderby=Id desc

MSDN

7
  • Sandip might want to ordered by Created or Modified instead of ID. Commented Nov 21, 2014 at 15:56
  • Once you put parenthesis Products() it can be ordered by any field. Commented Nov 21, 2014 at 16:10
  • 1
    @AmalHashim I think you need ID instead of Id. @james-grizzle why would Created be better than ID, wouldn't it be the same? And Modified would not be the last created item. Commented Nov 21, 2014 at 20:48
  • @eirikb is correct. Commented Nov 21, 2014 at 21:00
  • @AmalHashim, parenthesis are not mandatory and @eirikb it is Id and not ID. FYI, orderby doesn't work if top is not used. See here: sharepoint.stackexchange.com/questions/58188/… Commented Nov 24, 2014 at 6:53

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.