I am using API call to fetch news items from a custom list, and filter by its date and then orderby news item's title. However orderby clause never works, if I put $orderby before $filter, then filter clause stop working.

Here is my CAML query:

&$filter=StartDate le datetime' + midnightDayIsoString + ' and Expires ge datetime' + midnightDayIsoString + '

midnightDayIsoString is defined by using new Date() function, calling .toISOString() method, and replace the time parts with hardcoded 12:00:00Z. e.g. datetime('2017-08-15T12:00:00Z')

API call is using ajax:

            url:  siteurl + query,
            method: "GET",
            headers: {"Accept": "application/json; odata=verbose"},
            RowLimit: null,     
            RowsPerPage: null,  

The query returns correct filtered result, but does not do the $orderby part.

I don't know that why orderby is not working. I need some help on this. Thanks.

  • I am using SharePoint 2013.
    – Alan
    Commented Aug 15, 2017 at 0:24
  • are you missing the ? between ../items?$select=...
    – Mike
    Commented Aug 15, 2017 at 0:29
  • Sorry that was my typo when I was entering the question, I will correct that. Thanks for pointing it out.
    – Alan
    Commented Aug 15, 2017 at 0:34
  • Can you show us your entire code including how you are deriving midnightDayIsoString?
    – Mike
    Commented Aug 15, 2017 at 1:04
  • I've just update the post with some code sample in there, actually quite standard.
    – Alan
    Commented Aug 15, 2017 at 1:40

2 Answers 2


If you have the dates already as an ISO string, you don't need the datetime parser in REST.


var query = "/_api/web/lists(guid'CE7A5EC9-D264-48D9-8F81-1C2F8C7341XX')/items?
&$filter=StartDate le '" + midnightDayIsoString + "' and Expires ge '" + midnightDayIsoString + "'

Try with

&$orderby=Title asc
or &$orderby=Title desc

If you didn't get expected results then try without filter in query like as bellow.


If you got results in sorting order then you need check filter condition in URL.

Hope this helps you.

  • thanks for your answer. I tied this before, it worked. It was a bit strange when i put both $filter and $orderby parameter, then the results didn't get sorted. But just minutes ago, it starts working that I cannot explain why worked.
    – Alan
    Commented Aug 15, 2017 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.