How to sort entries directly from url

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…&?sort= like this
I want to order my entries by created date. Am I missing something here ?

Thank you :slight_smile:

and

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

see also:

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

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

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
-> the entry with the title “b” is returned first

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

so whats the problem?

use -1 for DESC ordering and 1 for ASC

Thank you @serjoscha87, It works!:+1::+1:, 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”

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

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.

1 Like

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.

I just quoted the complete post. But thaks :slight_smile:

Hello its me again :slight_smile:
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.

Again not quite sure, but I dont think so.

Maybe you should try the graphql addon: https://github.com/agentejo/CockpitQL