How to get quantity number of my entries

If you send a request to example.com/api/collections/get/elements?token=xxtokenxx, the response should look like this:

{
"fields": {...},
"entries": [...],
"total": 5
}

The total is your count.

If you want a smaller size of the response, use the fields filter, so the entries object only contains the _id.

If you want a rest api endpoint, that only counts, you have to create your own:

/config/api/collections/count/elements.php:

<?php
// check filters
$options = [];
return ['total' => cockpit('collections')->count('elements', $options)];

Have a look at the RestApi controller to see how the core filtering works:

1 Like