# Is webhook on custom sort possible?

**URL:** <https://discourse.getcockpit.com/t/is-webhook-on-custom-sort-possible/1149>\
**Category:** Uncategorized\
**Created:** [January 13, 2020, 1:45pm UTC](https://discourse.getcockpit.com/t/is-webhook-on-custom-sort-possible/1149 "2020-01-13T13:45:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrtn](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrtn](https://discourse.getcockpit.com/u/mrtn)\
**Post date:** [January 13, 2020, 1:45pm UTC](https://discourse.getcockpit.com/t/is-webhook-on-custom-sort-possible/1149/1 "2020-01-13T13:45:53Z")

</div>

Hi, all,

I am trying to trigger a webhook after moving around custom sortable entries in a collection. collections.updatecollection and collections.save.after don’t trigger on reordering. Is there any event that does?

Thanks!

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [January 18, 2020, 2:52pm UTC](https://discourse.getcockpit.com/t/is-webhook-on-custom-sort-possible/1149/2 "2020-01-18T14:52:47Z")

</div>

Sorry, there is no event, yet.

Have a look here:

> <https://github.com/agentejo/cockpit/blob/next/modules/Collections/Controller/Admin.php#L360-L378>

You could change it and send a pull request.

I’m not sure about the best logic and naming convention here… I would suggest to use the same logic like the core save function

> <https://github.com/agentejo/cockpit/blob/next/modules/Collections/bootstrap.php#L370-L380>

or to create a new event, e. g.:

```php
    if (is_array($entries) && count($entries)) {

        $this->app->trigger('collections.admin.updateorder.before', [$collection['name'], &$entries]);

        foreach($entries as $entry) {
            $this->app->storage->save("collections/{$_collectionId}", $entry);
        }

        $this->app->trigger('collections.admin.updateorder.after', [$collection['name'], $entries]);
    }

```

---

<div class="post-metadata">

**Author:** ![lastfuture](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/lastfuture/32/699_2.png) [@lastfuture](https://discourse.getcockpit.com/u/lastfuture)\
**Post date:** [October 22, 2020, 10:16pm UTC](https://discourse.getcockpit.com/t/is-webhook-on-custom-sort-possible/1149/3 "2020-10-22T22:16:33Z")

</div>

> [@raffaelj](#):
>
> ```auto
> if (is_array($entries) && count($entries)) {
> 
> $this->app->trigger('collections.admin.updateorder.before', [$collection['name'], &$entries]);
> 
> foreach($entries as $entry) {
> $this->app->storage->save("collections/{$_collectionId}", $entry);
> }
> 
> $this->app->trigger('collections.admin.updateorder.after', [$collection['name'], $entries]);
> }
> 
> ```

I tried your suggestion and it works and does trigger, however unfortunately it also triggers when all I do is open the collection before doing any more with it. That does seem to me like I might have uncovered a possible bug. I can’t imagine that it’s intentional that `update_order` gets called simply by displaying the sortable list, right?

---

<div class="post-metadata">

**Author:** ![lastfuture](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/lastfuture/32/699_2.png) [@lastfuture](https://discourse.getcockpit.com/u/lastfuture)\
**Post date:** [October 22, 2020, 10:25pm UTC](https://discourse.getcockpit.com/t/is-webhook-on-custom-sort-possible/1149/4 "2020-10-22T22:25:06Z")

</div>

I’m sorry, I have to correct myself. My webhook didn’t save correctly and it was still listening for `collections.find.before` instead of `collections.admin.updateorder.before`. My bad. The solution actually works beautifully.

---

<div class="post-metadata">

**Author:** ![oboogy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/oboogy/32/680_2.png) [@oboogy](https://discourse.getcockpit.com/u/oboogy)\
**Post date:** [December 23, 2020, 11:20pm UTC](https://discourse.getcockpit.com/t/is-webhook-on-custom-sort-possible/1149/5 "2020-12-23T23:20:37Z")

</div>

I spent some time trying to decipher the code above. I got it working perfectly now!! Thank you. But renamed to collections.customsort…

I really think this should be pushed into the repo. Can I help.

I barely have any use cases where its not needed. If you use web hooks on collections at all than most likely you have to catch the custom sort function.
