# How to sort entries directly from url

**URL:** <https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253>\
**Category:** Support\
**Created:** [September 7, 2018, 9:14pm UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253 "2018-09-07T21:14:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahi008](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@mahi008](https://discourse.getcockpit.com/u/mahi008)\
**Post date:** [September 7, 2018, 9:14pm UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/1 "2018-09-07T21:14:11Z")

</div>

Hello Community,  
I’ve just started using cockpit as my iOs app backend, everything works great  
but I don’t know how & I didn’t find anywhere to pass ‘sort’ param in the url.

for example [xxx.com/api/collections/get/myName/?token=XXX](http://xxx.com/api/collections/get/myName/?token=XXX)…&?sort= like this  
I want to order my entries by created date. Am I missing something here ?

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [September 7, 2018, 9:45pm UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/2 "2018-09-07T21:45:18Z")

</div>

![image](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/1X/cafad994ee8d4eee998cfb3780886492d2103460.png)

and

> [@Make rest api return rows in sorted order in new cockpit version](https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60/2):
>
> Hi,
> 
> please try the following:
> 
> `?sort[_o]=1`
> 
> Greets,  
> Artur

where the part within the brackets can be every field name of your collection (I guess)

see also:

> [@Search itens by term](https://discourse.getcockpit.com/t/search-itens-by-term/70/9):
>
> /api/collections/get/products?filter[$and][0][name]=Iphone&filter[$and][1][name]=Samsung

I guess sorting should be applied to URL the same way as filtering is

---

<div class="post-metadata">

**Author:** ![mahi008](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@mahi008](https://discourse.getcockpit.com/u/mahi008)\
**Post date:** [September 7, 2018, 10:26pm UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/3 "2018-09-07T22:26:38Z")

</div>

Well I tried both &filter[\_created]=1 and  
&sort[\_created]=1 either way no change in the output. As there’s no clear and concise documentation for the filtering and sorting within the url, I’m pretty much lost !

Anyway thank you @serjocha87

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [September 8, 2018, 10:01am UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/4 "2018-09-08T10:01:23Z")

</div>

for me it works pretty well.

I set up a simple test collection (named “test”) with just a title and a content field.

It added two entries (one with title “a” and one with title “b”).

[http://cockpit.local/api/collections/get/test?sort[title]=-1](http://cockpit.local/api/collections/get/test?sort%5Btitle%5D=-1)  
-\> the entry with the title “b” is returned first

[http://cockpit.local/api/collections/get/test?sort[title]=1](http://cockpit.local/api/collections/get/test?sort%5Btitle%5D=1)  
-\> the entry with the titel “a” is returned first

so whats the problem?

use -1 for DESC ordering and 1 for ASC

---

<div class="post-metadata">

**Author:** ![mahi008](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@mahi008](https://discourse.getcockpit.com/u/mahi008)\
**Post date:** [September 8, 2018, 11:12am UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/5 "2018-09-08T11:12:15Z")

</div>

Thank you @serjoscha87, It works!👍👍, the issues was that I added “&?sort” instead of “&sort”  
as my access token was active,I had to do it like this “/api/collections/get/name?token=xxxxx&sort[\_created]=-1”

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [September 8, 2018, 11:35am UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/6 "2018-09-08T11:35:00Z")

</div>

then your sould perhaps read about how to generally use URL query strings 😃

the order of params does not matter at all but query parameter are always initialized using a question mark. Any further param passed to the URI needs a **&** in front of the var name.

---

<div class="post-metadata">

**Author:** ![unenouvelleville](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/unenouvelleville/32/83_2.png) [@unenouvelleville](https://discourse.getcockpit.com/u/unenouvelleville)\
**Post date:** [September 11, 2018, 7:13am UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/7 "2018-09-11T07:13:09Z")

</div>

> [@serjoscha87](#):
>
> see also:
> 
> ![](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/40/4_1.png)[Search itens by term](https://discourse.getcockpit.com/t/search-itens-by-term/70/9)
> 
> > /api/collections/get/products?filter[$and][0][name]=Iphone&filter[$and][1][name]=Samsung
> 
> I guess sorting should be applied to URL the same way as filtering is

Hi Serjoscha,

Please take note that it’s not possible to make a filter AND & AND, you will receive no value and no error. Use OR instead of AND.

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [September 11, 2018, 7:39am UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/8 "2018-09-11T07:39:43Z")

</div>

I just quoted the complete post. But thaks 🙂

---

<div class="post-metadata">

**Author:** ![mahi008](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@mahi008](https://discourse.getcockpit.com/u/mahi008)\
**Post date:** [September 21, 2018, 3:34pm UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/9 "2018-09-21T15:34:22Z")

</div>

Hello its me again 🙂  
One last question, is there any endpoint which allows to get all collections + entries in one request ? (so I can get all data in one api reqquest instead of firing a request for each and every collection.

Thank you.

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [September 21, 2018, 9:06pm UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/10 "2018-09-21T21:06:03Z")

</div>

Again not quite sure, but I dont think so.

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [September 22, 2018, 10:27am UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/11 "2018-09-22T10:27:01Z")

</div>

Maybe you should try the graphql addon: [https://github.com/agentejo/CockpitQL](https://github.com/agentejo/CockpitQL)

---

<div class="post-metadata">

**Author:** ![artemijeka](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artemijeka/32/1290_2.png) [@artemijeka](https://discourse.getcockpit.com/u/artemijeka)\
**Post date:** [February 18, 2023, 9:21am UTC](https://discourse.getcockpit.com/t/how-to-sort-entries-directly-from-url/253/13 "2023-02-18T09:21:13Z")

</div>

![image](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/2X/6/62cedd4cb882c2c487d620721995edea48664f6b.png)
