Custom API - get singletons by slug

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]);

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:


// 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;

1 Like