# Filters for listCollections?

**URL:** <https://discourse.getcockpit.com/t/filters-for-listcollections/786>\
**Category:** Uncategorized\
**Created:** [April 26, 2019, 5:25pm UTC](https://discourse.getcockpit.com/t/filters-for-listcollections/786 "2019-04-26T17:25:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eeight](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@eeight](https://discourse.getcockpit.com/u/eeight)\
**Post date:** [April 26, 2019, 5:25pm UTC](https://discourse.getcockpit.com/t/filters-for-listcollections/786/1 "2019-04-26T17:25:17Z")

</div>

Hi,  
The documentation doesn’t talk about filters on collections (or in general for that matter)?  
[https://getcockpit.com/documentation/api/collections](https://getcockpit.com/documentation/api/collections)

I am trying to build a wiki using Cockpit (thanks @artur for sharing this project). I want to listCollections but only those matching Group: wiki (or any other alternative).

Possible or not?  
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:** [April 26, 2019, 5:56pm UTC](https://discourse.getcockpit.com/t/filters-for-listcollections/786/2 "2019-04-26T17:56:18Z")

</div>

It’s not possible by default, but you can write your own api endpoint and return the filterered collections. Create a file in `/cockpit/config/api/collections/myOwnEndpoint.php`

```php
$collections = $this->module('collections')->getCollectionsInGroup();
// check the array
return $collections;

```

That’s the original function:

> <https://github.com/agentejo/cockpit/blob/next/modules/Collections/Controller/RestApi.php#L241>

---

<div class="post-metadata">

**Author:** ![eeight](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@eeight](https://discourse.getcockpit.com/u/eeight)\
**Post date:** [April 26, 2019, 6:01pm UTC](https://discourse.getcockpit.com/t/filters-for-listcollections/786/3 "2019-04-26T18:01:27Z")

</div>

@raffaelj Thank you so much for replying so fast! I was looking at this method too (in RestApi.php) and I was wondering if it was possible to use the getCollectionsInGroup (as user)?

---

<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:** [April 26, 2019, 6:24pm UTC](https://discourse.getcockpit.com/t/filters-for-listcollections/786/4 "2019-04-26T18:24:06Z")

</div>

I’m not quite sure, what you mean. The function `getCollectionsInGroup()` returns only collections with the user group permissions. But if you don’t care about user groups, than do

```php
<?php
$collections = $this->module('collections')->collections();
$filtered = [];
foreach($collections as $collection) {
    if (isset($collection['group'] && $collection['group'] == 'wiki') {
        $filtered[] = $collection;
    }
}

```

or something similar.
