API Inside-Out – A Tour of Kaltura’s API Driven Architecture

The fact Kaltura is open sourced provides users of the Kaltura platform with many advantages. Amongst which, the ability to shape and influence the platform and its roadmap by contributing code to the project.
Very often, when building a new integration or a publishing workflow, it’s a bit too much to dive into the core platform code. With Kaltura you don’t have to!
Kaltura is a RESTful API and Microservices driven platform.
This means that all features, user facing or internal, are based on the same unified API broken down by services that are atomic and independent.
From upload and transcoding to playback and analytics, all platform components are controlled via the same unified API. Even the platform internals such as managing backend nodes, account configurations, etc.
A RESTful API follows these basic concepts:

  • It’s uniform – in Kaltura, every service represents an object, and actions represent its methods . For example: the media service represents the KalturaMediaEntry object. The media.delete action deletes a given KalturaMediaEntry object.
  • It’s stateless – In every API call you must provide a valid session key (dubbed KS). You can create as many sessions as you need at the same time.
  • It’s cache-able – Scale is a make or break with video applications and caching is a mandatory component.
  • Layered System – Clients have a single end point. Intermediary servers improve system scalability by enabling load-balancing and shared caches. Layers also enforce security policies and enhance system resilience.

A lot of projects offer a RESTful API. But what I believe makes the Kaltura API special is –
It’s API from the inside out!
The platform’s own components also use the same APIs to get their job done. This means core developers build and test using the same APIs that App developers use. Which in turn tests and improves the APIs daily.
Always up-to-date SDKs
Kaltura’s API features a unique automatic generation of SDK. With every release Kaltura generates new client libraries. Which are available for most popular programming languages, including: PHP, Ruby, Python and JavaScript.
See the client libraries page for complete list and downloads.
It’s Robust, Allowing Complete Control
The API is capable of controlling pretty much any operation in the platform’s core components. From ingesting content through management and transcoding, to playback, delivery, distribution and analytics.
To further explain point A, let’s dive into the Kaltura architecture:

The API and Client Libraries are used across the platform’s components, both in external applications such as Kaltura MediaSpace and various modules for 3rd party systems such as Drupal or WordPress, as well as internally, within the core Kaltura components such as transcoding, batch servers or the platform’s Admin Console.
For example, the batch daemon, responsible for performing roles such as: media import, media info extraction, transcoding and server notifications, triggers these APIs the same way any other party, like, your own application, would: using the Kaltura API Client libraries.
Here is a short example of how the APIs (in this particular case, using the PHP client lib) can be used to upload a new video entry to the system:

// require the Kaltura PHP5 client libs:
// generate a KS and return a client to work with:
function generate_ks($service_url,$partnerId,$secret,$type=KalturaSessionType::ADMIN,$userId=null,$expiry = null,$privileges = null)
   $config = new KalturaConfiguration($partnerId);
   $config->serviceUrl = $service_url;
   $client = new KalturaClient($config);
   $ks = $client->session->start($secret, $userId, $type, $partnerId, $expiry, $privileges);
   return ($client);
function upload($client,$fileData,$title,$conv_profile=null,$type=null)
    $uploadToken = new KalturaUploadToken();
    $result = $client->uploadToken->add($uploadToken);
    $resume = null;
    $finalChunk = null;
    $resumeAt = null;
    $result = $client->uploadToken->upload($tok, $fileData, $resume, $finalChunk, $resumeAt);
    $entry = new KalturaBaseEntry();
    $entry->name = $title;
    if (isset($conv_profile)){
       $entry->conversionProfileId = $conv_profile;
    if (!isset($type)){
      $type = KalturaEntryType::AUTOMATIC;
    $result = $client->baseEntry->addfromuploadedfile($entry, $tok, $type);
  }catch(exception $e){
    throw $e;
// call generate_ks() to instantiate a Kaltura client and start a session
// pass $client object and $video_file to upload() function to upload and create the new entry
$id=upload($client,$video_file,"Entry's name",null,null);

Having an API driven architecture enables complete control and freedom with how you want your application workflows and UI to behave. From creating different publishing workflows to exposing sets of functionalities.
In addition, the API inside-out approach opens up many opportunities for adapting, controlling and extending beyond the simple UI workflows and apps, important examples for that are platform automation and monitoring tools.

Playing with the API:
As mentioned, Kaltura provides client libs generated for various programming languages. In addition, API calls can be made using a testing tool dubbed the Kaltura TestMe console.
The first thing you would want to do is create a Kaltura Session – KS:

  1. Select ‘session’ as service and ‘start’ as action.
  2. In session type, select ‘USER’.
  3. The secret field corresponds to one of two strings that are saved in Kaltura for each partner and are available in your KMC under the Settings>Integration Settings tab. Note that there are two types of secrets, one that can be used to start a USER session and one to start an ADMIN session.

If you look at the screenshot above, you will see that, in the right frame, we have the returned XML which includes:

  • The result tag with the KS ‘N2E1NGE1NGIxOGFlNWI3MDU1NWY4YTNmMjM2QwZDg2ZDA1YjM0MHwyNDk7MjQ5OzEzOTkyODc1OTA7MDsxMzk5MjAxMTkwLjM1NDs7Ozs=’ as value
  • The executionTime tag with 3.71932983398 as value

At the bottom of the page, you can see the code our selections in the input form generated.
Notice that while the default displayed code is in PHP, you can click on one of the other languages to see the code generated for them.

As a second example for using the Test Me Console, we will list the entries our partner owns, by using the baseEntry service and calling its listAction() action.
As you can see, the generated code reads:

$config = new KalturaConfiguration($partnerId);
$config->serviceUrl = '';
$client = new KalturaClient($config);
$filter = new KalturaBaseEntryFilter();
$filter->statusEqual = KalturaEntryStatus::READY;
$result = $client->baseEntry->listAction($filter, $pager);

If you run this code and add:


You will get a result very similar to the XML outputted in the right frame of the page in the screenshot above.

The Test Me Console is a useful method for exploring the Kaltura API. Simply browse through available services and see what actions can be made.
Then, you can copy the code snippet and shape it into something useful within your scripts.

Hopefully this article will help you get started with the Kaltura APIs.
Browse the Kaltura API Documentation Set to learn more and explore more Kaltura APIs.
For questions, leave a comment below, or start a thread in the forums.
Download, install and take part in the Community.

Happy coding 🙂

The Video Experience Hackathon endded. You can explore the winning projects at:

Let's Get Going