# Custom API - get singletons by slug

**URL:** <https://discourse.getcockpit.com/t/custom-api-get-singletons-by-slug/840>\
**Category:** Support\
**Created:** [May 20, 2019, 9:08am UTC](https://discourse.getcockpit.com/t/custom-api-get-singletons-by-slug/840 "2019-05-20T09:08:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelsmith](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/rafaelsmith/32/320_2.png) [@rafaelsmith](https://discourse.getcockpit.com/u/rafaelsmith)\
**Post date:** [May 20, 2019, 9:08am UTC](https://discourse.getcockpit.com/t/custom-api-get-singletons-by-slug/840/1 "2019-05-20T09:08:33Z")

</div>

Hey!  
I wanted to know if it’s possible to get singletons by slug or another field?  
right now I get the singletons by this code, but some time the url not the some as the name

> cockpit(‘singletons’)-\>getData($collection, [‘populate’ =\> 1, ‘lang’ =\> $lang]);

---

<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:** [May 21, 2019, 3:12pm UTC](https://discourse.getcockpit.com/t/custom-api-get-singletons-by-slug/840/2 "2019-05-21T15:12:22Z")

</div>

This is not possible by default. If you want to filter them, use collections instead.

But you could create a custom api endpoint and fiddle with the results:

```php
<?php

// custom api endpoint in `/config/api/singletons/find.php`

// Your Singletons with a field named "title"
// Search all Singletons with the title "test"
// tested with SQLite - I don't know, if it works with Mongo, too

$options = [
    'filter' => [
        'val.title' => 'test',
    ],
];

$singletons = $this->storage->find('singletons', $options);

return $singletons;

```

---

<div class="post-metadata">

**Author:** ![Lydie](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@Lydie](https://discourse.getcockpit.com/u/Lydie)\
**Post date:** [June 19, 2024, 2:05pm UTC](https://discourse.getcockpit.com/t/custom-api-get-singletons-by-slug/840/3 "2024-06-19T14:05:42Z")

</div>

Hi, sorry to undig a really old post.  
When i try your solution Raffaelj, i get an error on storage.  
We are using v2.8.3 version of cockpit  
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:** [June 19, 2024, 3:17pm UTC](https://discourse.getcockpit.com/t/custom-api-get-singletons-by-slug/840/4 "2024-06-19T15:17:31Z")

</div>

This solution is for cockpit v1 (or 0.x), like most of the threads in this forum. Can’t help here because I stopped using Cockpit after the rewrite to v2.
