---
title: API Filters
url: https://docs.kaltura.com/docs/embeddable-kaltura-products/media-manager/api-filters
---

## API Filters

`apiFilters.getMediaList` narrows the media list with declarative conditions, such as "videos owned by Jane" or "entries in these categories". It only narrows: it is applied on top of the context, media-type and search filters, and never shows more than they allow.

```js
settings: {
  context: {
    type: 'myMedia',
    apiFilters: {
      getMediaList: {
        orConditions: [
          {
            andConditions: [
              { type: 'byMediaType', mediaTypesList: ['1'] },
              { type: 'byUser', userIds: ['jane@example.com'] },
            ],
          },
        ],
      },
    },
  },
}
```

### How Conditions Combine

The filter is an **OR of ANDs**:

- `orConditions` is a list of groups. An entry is listed if it matches **any** group.
- Each group's `andConditions` is a list of conditions. An entry matches the group only if it matches **all** of them.

So this lists videos owned by Jane, **or** anything in category 12345:

```js
getMediaList: {
  orConditions: [
    { andConditions: [
      { type: 'byMediaType', mediaTypesList: ['1'] },
      { type: 'byUser', userIds: ['jane@example.com'] },
    ] },
    { andConditions: [
      { type: 'byCategory', categoryIds: ['12345'] },
    ] },
  ],
}
```

### Conditions

| `type` | Fields | Matches entries that… |
|---|---|---|
| `byMediaType` | `mediaTypesList: string[]` | Have any of these `KalturaMediaType` values: `'1'` video, `'2'` image, `'5'` audio. |
| `byUser` | `userIds: string[]`, `roles?: string[]` | Have any of these users in any of these roles. See the roles below. |
| `byCategory` | `categoryIds: string[]`, `matchDescendants?: boolean`, `exclude?: boolean` | Are in any of these categories. `matchDescendants: true` also matches their subcategories. `exclude: true` instead lists entries **not** in them. |
| `byObjectStatus` | `statusList: string[]` | Have any of these `KalturaEntryStatus` values, for example `'2'` ready. |
| `byESearchObjects` | `filter: { objectType, ... }` | Match a raw eSearch item you provide, such as `KalturaESearchEntryItem`. Use it for fields the other conditions don't cover. |

#### `byUser` Roles

| Role | Matches entries the user… |
|---|---|
| `owner` (default) | Owns |
| `creator` | Created |
| `coEditor` | Can edit as a co-editor |
| `coPublisher` | Can publish as a co-publisher |
| `coViewer` | Can view as a co-viewer |

With several roles, an entry matches if the user has any of them:

```js
{ type: 'byUser', userIds: ['jane@example.com'], roles: ['owner', 'coEditor'] }
```

To include a user's groups, add the group IDs to `userIds`.

#### `byObjectStatus` Applies to the Whole List

Entry status isn't a per-group field in eSearch, so the statuses from every `byObjectStatus` condition are combined and applied to the whole list. They can only narrow the statuses the table already lists, which include ready, processing, pending and failed entries. To list other statuses, use the [`preGetMediaList` interceptor](/docs/embeddable-kaltura-products/media-manager/interceptors).

#### `byESearchObjects`

Pass any eSearch item as a plain object, with its `objectType`:

```js
{
  type: 'byESearchObjects',
  filter: {
    objectType: 'KalturaESearchEntryItem',
    fieldName: 'tags',
    searchTerm: 'approved',
    itemType: 1,
  },
}
```

`itemType` is `1` for an exact match and `2` for a partial match. See the [eSearch API](/docs/rich-media-cms-apis/content-management/esearch-overview) for fields and item types.

### Mistakes Fail Loudly

Unlike interceptors, API filters **fail closed**. A malformed filter never silently widens the list; instead the list shows an error, and the console logs a message starting with `apiFilters.getMediaList:` that says what is wrong. This happens for:

- An unknown condition `type` or `byUser` role.
- A field of the wrong shape, for example a string where an array is expected, or `exclude: 'false'` instead of `false`.
- A `byESearchObjects.filter` without a string `objectType`.

A group that ends up empty is dropped rather than treated as "match everything".

### Order of Operations

For each list request:

1. The table builds its query from the context, media-type filter and search box.
2. `apiFilters.getMediaList` narrows it.
3. The [`preGetMediaList` interceptor](/docs/embeddable-kaltura-products/media-manager/interceptors), if any, sees the result and can change it further.
