# Make rest api return rows in sorted order in new cockpit version

**URL:** <https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60>\
**Category:** Support\
**Created:** [May 17, 2018, 7:33am UTC](https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60 "2018-05-17T07:33:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jb-storms-media](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jb-storms-media](https://discourse.getcockpit.com/u/jb-storms-media)\
**Post date:** [May 17, 2018, 7:33am UTC](https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60/1 "2018-05-17T07:33:23Z")

</div>

hey,

before some time the rest api returned the results of a collection in the order the user set them in cockpit (by dragging around).

Today the Rest result ordering seems to be done by the row ID or something and there is a new field “\_o” in the collection row data. How do I get the Collection RestAPI to return rows in the order that the user has defined in cockpit (by dragging collection rows/entries around)?

I took a look at the collection controller which contains

if ($sort = $this-\>param(‘sort’, null)) $options[‘sort’] = $sort;

but when I put ?order= at the end of the rest api call I get an internal server error.

Thanks ahead

---

<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:** [May 17, 2018, 7:41am UTC](https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60/2 "2018-05-17T07:41:42Z")

</div>

Hi,

please try the following:

`?sort[_o]=1`

Greets,  
Artur

---

<div class="post-metadata">

**Author:** ![jb-storms-media](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jb-storms-media](https://discourse.getcockpit.com/u/jb-storms-media)\
**Post date:** [May 17, 2018, 7:43am UTC](https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60/3 "2018-05-17T07:43:57Z")

</div>

perfect, works like a charm! thanks!

---

<div class="post-metadata">

**Author:** ![JesperWe](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperwe/32/32_2.png) [@JesperWe](https://discourse.getcockpit.com/u/JesperWe)\
**Post date:** [May 20, 2018, 6:33am UTC](https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60/4 "2018-05-20T06:33:01Z")

</div>

No, unfortunately that does not “work like a charm” at all. \_o starts at zero in each folder in the new hierarchical sorting, so as soon as you have multiple folder this totally messes up the sort order compared to what you see in the Cockpit UI view. @artur you said on Gitter previously:

> yes, this is still missing but will get implemented soon

… is that still 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:** [May 20, 2018, 10:42am UTC](https://discourse.getcockpit.com/t/make-rest-api-return-rows-in-sorted-order-in-new-cockpit-version/60/5 "2018-05-20T10:42:08Z")

</div>

@jb-storms-media wanted a quick solution for not nested entries. But to answer your question: yes, the implementation will come, but I need to finish some contract work first.

Greets  
Artur
