Custom API - get singletons by slug

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

1 Like

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

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

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

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.

1 Like