Fetch collection definitions / meta data

Is it possible to fetch the underlying (structural) JSON for any given collections in a space?
I’d like to write a small tool that takes a space endpoint and API key and then generates TypeScript interfaces for all the collection data that is available.


Collection: BlogPosts
 - field title: Text (req)
 - field content: WYSIWYG
 - ...
// Generated TypeScript interface
 export interface BlogPost {
    title: string
    content?: string
    published: boolean

I’d be happy to share the results with the community when done.

You can create a custom api endpoint. Just create the file /path/to/cockpit/config/api/model.php.


$modelName = $this->param('model');

if (!$modelName) {
    return $this->stop(['error' => "model parameter missing"], 412);

// TODO: permission checks

$model = $this->module('content')->model($modelName);

if (!$model) {
    return $this->stop(['error' => "Model <{$modelName}> not found"], 404);

// TODO: filter sensitive data

return $model;

Now you can access the model data via https://example.com/api/model?model=BlogPosts.

1 Like