# Retrieve assets by folders

**URL:** https://discourse.getcockpit.com/t/retrieve-assets-by-folders/1353
**Category:** Support
**Created:** [April 13, 2020, 10:26am UTC](https://discourse.getcockpit.com/t/retrieve-assets-by-folders/1353 "2020-04-13T10:26:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![seanmavley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/seanmavley/32/210_2.png) [@seanmavley](https://discourse.getcockpit.com/u/seanmavley)
#### Post date: [April 13, 2020, 10:26am UTC](https://discourse.getcockpit.com/t/retrieve-assets-by-folders/1353/1 "2020-04-13T10:26:15Z")

</div>

I have a folder, let’s say ‘gallery’

I can currently get all assets with the [https://getcockpit.com/documentation/api/cockpit](https://getcockpit.com/documentation/api/cockpit)

`/api/cockpit/assets?token=xxtokenxx'`

If I want to filter assets only within the `gallery` folder, how will I go about that?

Is it possible to use a custom query passed along in the `body` of the request to do that?

Currently what I’m thinking of a workaround is simply getting all the assets, then filtering locally in the browser, based on a tag, which I’ll have to set on all the images within the gallery folder.

---

<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: [April 13, 2020, 5:03pm UTC](https://discourse.getcockpit.com/t/retrieve-assets-by-folders/1353/2 "2020-04-13T17:03:22Z")

</div>

> [@seanmavley](#):
>
> /api/cockpit/assets?

Yes, you need to pass the `folder id` in the filter like:

```auto
{
	"filter": {
		"folder": "5e3c2582132d6b00584168f2"
	}
}

```

Issue is that you may need to do a query first to get the folder ids and if not wrong the core API doesn’t provide that, but you can add it like:

Create a new file in `config/api/`, e.g. `config/api/folder.php`

```auto
<?php

return $this->storage->findOne('cockpit/assets_folders', ['name' => $this->param('name')]);

```

So if you invoke the endpoint `/api/folder?token=xxxx&name=FolderX` you’ll receive the folder data:

```auto
{
  "_id": "5e3c2ceb132d6b00584168f3",
  "name": "FolderX",
  "_p": "",
  "_by": "5d8e7300d54909004c78b6c2"
}

```
