I am trying to search for media by category via API. Using media.list I can filter by Tags filter[tagsLike] without a problem at all but I can’t seem to search by Category. I get zero return.
I then tried to use categoryEntry.list to search but I am betting the following error: OBJECT_TYPE_ABSTRACT: The object type “KalturaSearchItem” is abstract, use one of the object implementations even if i do have a ‘search word’ in filter[…]. I tried different field but yield the same results.
I am doing all of this in the Kaltura Test Console before I code it in Python/Flask or Node.js. Still debating.
From the test console, you can do it by choosing media as service, list as action, click on edit above the filter field, check “categoriesIdsMatchOr” and input the category ID you’re interested in. You also have categoriesIdsMatchAnd and categoriesMatchAnd categoriesMatchOr if you want to search by category names instead of IDs.
All these can accept one or more category names/IDs, comma separated.
The Python parallel of this, which will return entries attached to category ID 15, would be along the lines of:
If you’re not getting a result using this, make sure there really are entries attached to that category. A good way to check is to find an entry you think is attached to it, call media.get() to make sure it returns with:
Thank you. After reading your response, I was wondering what I was doing wrong because I did pretty much the same except instead of filter.categoriesIdsMatchOr=15, I used filter.categoriesMatchOr= , but I wasn’t getting the results I was expecting.
You’re last section triggered me to look at the categories/id and when I did a media.listAction and did see the media I was looking for.
After hitting the “Send Reguest” button, it was on Visual and I guess there is a limit of 5 content Items if I leave index and pager = null. That’s what led me to believe I was doing something wrong. When I switch to RAW, the data came pouring down. Sweet!
You didn’t include the KS generation code but my guess would be this category is configured to utilise the entitlement mechanism and that you did not pass ‘disableentitlement’ as part of the privileges param when calling session.start().
Here is a full sample code using the new AJAX client lib and generating a KS with the ‘disableentitlement’ privilege.
<html>
<head>
<script src="jquery-3.1.0.min.js"></script>
<script src="KalturaClient.min.js"></script>
<script src="KalturaSessionService.min.js"></script>
<script src="KalturaMediaService.min.js"></script>
<script src="KalturaCategoryService.min.js"></script>
<script>
$( document ).ready(function() {
var config = new KalturaConfiguration();
config.serviceUrl = 'https://www.kaltura.com';
var client = new KalturaClient(config);
// Note: this is meant only as a sample.
// You should NEVER generate sessions on the client,
// as this exposes your Admin Secret to users.
// Instead, generate a session on the server and pass the
// KS to the client.
KalturaSessionService.start(
ADMIN_SECRET,
"",
2,
PARTNER_ID,
null,
'disableentitlement')
.execute(client, function(success, ks) {
if (!success || (ks.code && ks.message)) {
console.log('Error starting session', success, ks);
} else {
client.setKs(ks);
var filter = {objectType: "KalturaMediaEntryFilter"};
filter.categoriesIdsMatchOr = 3018424;
var pager = {objectType: "KalturaFilterPager"};
KalturaMediaService.listAction(filter, pager)
.execute(client, function(success, results) {
if (!success || (results && results.code && results.message)) {
console.log('Kaltura Error', success, results);
} else {
console.log('Kaltura Result', results);
}
});
}
});
});
</script>
</head>
</html>
Do let me know should you have additional questions,
Most welcome. Glad to hear we’re good:)
Notice however that using JS to generate a session is not recommended, for the obvious reason that the admin secret will be available to anyone viewing the page source.