Create a custom API endpoint with everything but body content?

How would I create a custom API endpoint with everything but body_content?

Essentially, I want an index of all my posts – but I don’t want to query the body_content. (I’ll query that when I hit the actual page.)

I know I can create a custom API endpoint in my config folder – but I’m not sure of the correct syntax for this.

I have a custom endpoint that queries unpublished entries:

<?
return cockpit('collections')->find('posts', [ 'filter'=>array_merge($this->param('filter', []), ['published'=>false])]);
?>

Would removing the body from the response be similar to this? Essentially, I want to query:

postID, slug, title, and excerpt.

This should do the trick:

<?

return cockpit('collections')->find('posts', [ 
   'filter' => array_merge($this->param('filter', []), ['published'=>false]),
   'fields' => ['body_content' => 0] // get all fields except the body
]);

Greets,
Artur

1 Like

Awesome – thank you!

I changed the ‘-1’ to zero — and it worked perfectly. Thank you!!

Ahhh yes, sorry for that!