How do I search by category via API?

Hello Kaltura Community,

This is my first post to the Community.

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.

Thanks again,
-romeo

Hello,

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:

config = KalturaConfiguration(PARTNER_ID)
config.serviceUrl = "SERVICE_URL"
client = KalturaClient(config)
filter = KalturaMediaEntryFilter()
filter.categoriesIdsMatchOr=15
pager = None
result = client.media.list(filter, pager)

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:

 <categories>your_cat_name</categories>
 <categoriesIds>your_cat_id</categoriesIds>

Hello Jess,

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!

Thank you,
-romeo

Hi All,

I just tried that above. However I still get a 0 result.

When I retrieve my video via media.get(id) the categories are displayed correctly. When I try to query via

KalturaConfiguration config = new KalturaConfiguration();
config.setPartnerId(partnerId);
config.setEndpoint("");
KalturaClient client = new KalturaClient(config);
KalturaMediaEntryFilter filter = new KalturaMediaEntryFilter();
String filter.categoriesIdsMatchAnd = “”;
String filter.categoriesIdsMatchOr = 3018424;
String filter.referenceIdEqual = null;
KalturaFilterPager pager = null;
Object result = client.getMediaService().list(filter, pager);

it fails and returns .0 Any hints?

Hi @Boog,

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().

Regardless, from your sample code, it looks as though you’re not using the latest JS client. I recommend you obtain the latest from https://github.com/kaltura/KalturaGeneratedAPIClientsAJAX instead.

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,

Thank you so much. I switched from USER to ADMIN priviledges and everything worked fine.

Hi @Boog,

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.