API to return only certain fields depending on query

I have found various ways to have the cockpit GET api return only certain fields in a collection, but these ways seem to apply globally, essentially hiding certain fields of the collection (or even all collections). But we want to have different calls return different combinations of fields, for the given collection. The goal is to minimize the amount of (contextually irrelevant) data sent over the wire, so we do not want to place the filtering in the browser or have it affect all GETs from the collection.

We query Cockpit from Nuxtjs using axios with API calls like

Is there any way to use a parameter on the api url that would help us restrict which fields are returned?


1 Like

Just use the fields filter:


Now your entries should contain critical, title and _id. If you want to omit _id, you have to add &fields[_id]=0.

If you use a positive projection fields[title]=1, only specified fields and _id are returned.
If you use a negative projection fields[title]=0, all fields except title are returned.

Be aware, that filtering on an excluded field doesn’t work.


Thanks. That helped immensely.