# Do not include fields schema in rest api responses

**URL:** https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671
**Category:** Support
**Created:** [March 21, 2019, 9:40am UTC](https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671 "2019-03-21T09:40:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![morganlegal](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/morganlegal/32/274_2.png) [@morganlegal](https://discourse.getcockpit.com/u/morganlegal)
#### Post date: [March 21, 2019, 9:40am UTC](https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671/1 "2019-03-21T09:40:42Z")

</div>

Hello, I’m new to cockpit and I wonder if it’s possible not to have the schema of the fields in the rest api response : `{"name":"title","type":"text","localize":false,"options":[]}` for example.  
I’ve found the `simple=1` query parameter. It works great with most of the fields but not with the repeater field. Is there a solution? Because exposing the schema appears messy to me and consumes bandwidth. Thanks

---

<div class="post-metadata">

### Author: ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)
#### Post date: [March 21, 2019, 4:48pm UTC](https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671/2 "2019-03-21T16:48:10Z")

</div>

What I’m doing for those scenarios is to filter out stuff don’t want on the api answers using a `collections.find.after.<name>` trigger

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [March 21, 2019, 5:31pm UTC](https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671/3 "2019-03-21T17:31:06Z")

</div>

> [@morganlegal](#):
>
> I’ve found the `simple=1` query parameter.

Nice, I wasn’t aware of this option.

> [@morganlegal](#):
>
> It works great with most of the fields but not with the repeater field.

If you don’t need all options from the repeater field, maybe this custom field helps: [tag file](https://github.com/raffaelj/cockpit-scripts/blob/master/custom-fields/field-simple-repeater.tag), [usage](https://github.com/raffaelj/cockpit-scripts/blob/master/custom-fields/field-simple-repeater.md)

I wrote it three months ago to have a clean output from a repeater field. Than I didn’t use it, so I’m not sure, if it has any issues or which features from the original repeater field are missing.

---

<div class="post-metadata">

### Author: ![DrMartinGonzo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/drmartingonzo/32/249_2.png) [@DrMartinGonzo](https://discourse.getcockpit.com/u/DrMartinGonzo)
#### Post date: [March 21, 2019, 7:01pm UTC](https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671/4 "2019-03-21T19:01:19Z")

</div>

I made this in a custom addon. A bit messy, I’m no php developper, but it gets the job done for me. Not 100% tested though.

```php
if (COCKPIT_ADMIN && COCKPIT_API_REQUEST) {
    function remove_underscore_fields(&$array)
    {
        // don't remove "_pid", as it breaks sortable nested entries
        $toRemove = ["_o", "_by", "_mby", "_modified", "_created"];

        foreach ($toRemove as $name) {
            if (isset($array[$name])) {
                unset($array[$name]);
            }
        }
    }

    function make_simple(&$field)
    {
        if (is_array($field)) {
            remove_underscore_fields($field);

            foreach ($field as &$subentry) {
                // for fields like repeater, set...
                if (isset($subentry["field"])) {
                    unset($subentry['field']);
                }
                make_simple($subentry);
            }
        }
    }

    $simple_collection = function ($name, &$entries) use ($app) {
        $isSimple = $app->param('simple');
        if ($isSimple) {
            foreach ($entries as &$entry) {
                remove_underscore_fields($entry);
                foreach ($entry as &$field) {
                    make_simple($field);
                }
            }
        }
    };

    $simple_singleton = function ($singleton, &$data) use ($app) {
        $isSimple = $app->param('simple');
        if ($isSimple) {
            remove_underscore_fields($data);
            foreach ($data as &$field) {
                make_simple($field);
            }
        }
    };

    $app->on("collections.find.after", $simple_collection);
    $app->on("singleton.getData.after", $simple_singleton);
}

```

---

<div class="post-metadata">

### Author: ![morganlegal](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/morganlegal/32/274_2.png) [@morganlegal](https://discourse.getcockpit.com/u/morganlegal)
#### Post date: [March 21, 2019, 7:14pm UTC](https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671/5 "2019-03-21T19:14:56Z")

</div>

Wow! Thanks a lot. I’ll try that

---

<div class="post-metadata">

### Author: ![morganlegal](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/morganlegal/32/274_2.png) [@morganlegal](https://discourse.getcockpit.com/u/morganlegal)
#### Post date: [March 27, 2019, 6:50am UTC](https://discourse.getcockpit.com/t/do-not-include-fields-schema-in-rest-api-responses/671/6 "2019-03-27T06:50:14Z")

</div>

Works great anyway! Thanks!
