Skip to main content
View as Markdown

Interceptors - Media Manager

Interceptors​

Interceptors let you change each Kaltura API request before it is sent, and the entries after they load. Set them in interceptors inside context.

For simple narrowing, such as by user, category or media type, prefer API Filters.

InterceptorContextRuns on
preGetMediaListbothThe media-list query (eSearch.searchEntry)
preGetFolderscategory onlyThe folder query (category.list)
preGetProcessingListbothThe status check for entries still processing (baseEntry.list)
postGetMediaListbothThe entries returned by the media list and by processing checks

Edit Plain Objects​

Each pre* interceptor receives the request's query as a plain object. Edit it, then either return it or return nothing to keep your in-place edits:

interceptors: {
preGetFolders: (filter) => {
filter.tagsLike = 'public';
},
}

Don't construct Kaltura client library objects. The runtime uses its own copy of the client, so it rebuilds the real request from your plain object. Nested objects must carry their objectType.

preGetMediaList​

The media list is an eSearch query (KalturaESearchEntryParams). The interceptor receives it with these fields:

FieldDescription
searchOperatorThe root operator: { objectType, operator, searchItems }. operator is 1 for AND, 2 for OR, 3 for NOT.
objectStatusesComma-separated entry statuses to list.
orderByThe sort order.

To add a condition, push a plain eSearch item into the root operator, which is an AND:

interceptors: {
preGetMediaList: (query) => {
query.searchOperator.searchItems.push({
objectType: 'KalturaESearchEntryItem',
fieldName: 'tags',
searchTerm: 'approved',
itemType: 1, // 1 = exact match, 2 = partial
});
return query;
},
}

preGetMediaList runs after apiFilters.getMediaList, so it sees and can change the filtered query. See the eSearch API for item types and fields.

preGetFolders and preGetProcessingList​

These receive a classic list filter: KalturaCategoryFilter for folders, and KalturaBaseEntryFilter (or KalturaMediaEntryFilter) for processing checks:

interceptors: {
preGetFolders: (filter) => {
filter.orderBy = '+name';
return filter;
},
preGetProcessingList: (filter) => {
filter.tagsMultiLikeAnd = 'my-tag';
return filter;
},
}

Errors Don't Break the List​

pre* interceptors fail open: if one throws or returns something invalid, the table logs the problem in the console and still sends a valid query.

ProblemWhat happens
The interceptor throwsIt is ignored, and the unmodified query is sent.
It returns null, an array or a primitiveThe return value is ignored, and your in-place edits are sent.
A node has an unknown objectTypeThat node is dropped, and the rest of the query is sent.

Look for console errors that name the interceptor, for example preGetMediaList: unknown Kaltura objectType.

postGetMediaList​

postGetMediaList receives the entries after they load and before the table shows them. Use it to add data from your own systems, then display it with a custom column:

interceptors: {
postGetMediaList: async ({ entries, source, listContextId }) => {
const statuses = await fetchReviewStatuses(entries.map((e) => e.id));
return entries.map((e) => ({ ...e, reviewStatus: statuses[e.id] }));
},
}
ArgumentDescription
entriesThe loaded entries.
source'list' for a list page, or 'processing' for a status check on processing entries.
listContextIdThe current category ID, or empty in My Media.
  • Return the new array, or nothing to keep in-place edits. It can be async.
  • It also runs on processing checks, because each check replaces the row's data. Without that, fields you added would disappear when an entry finishes processing. Use source to skip work, for example for brand-new uploads your system doesn't know yet.
  • Unlike the pre* interceptors, it fails closed: if it throws or returns something other than an array, the list shows an error.