Adding a MediaSapce channel to a category via API

I’m currently looking for a way to associate a MediaSpace channel with and existing MediaSpace Gallery/category via the API. I know this can be done through MediaSpace’s web interface, however I haven’t yet found out how to do this from the API.

1 Like

Hi @jvlogwood,

This is accomplished by a combination of calls to the category, categoryuser and metadata APIs.
Just so we’re sure, can you describe the exact flow in MediaSpace you’d like to automate using API calls?
I’ll then allocate some time to put together a code sample later today.

Hey Jess,
Not to far in the future I’m going to need to set up about a hundred different MediaSpace channels, and probably more later on. I’m looking to essentially automate the functionality that is provided on the “Create a New Channel” page in order to save time. On the “Create a New Channel Page” in MediaSpace you are allowed to set a name, description, tags, privacy context, moderation, if comments are enabled or not, and the categories that this channel falls under. I’ve figured out how to do pretty much everything everything except for that last piece which is associating a channel to a category.

Also currently I’m not worried about associating users with the channels, other than the owner of the channel of course.

Any help you can give would be great.

Thanks,
James

Hey James,

Below are the needed API calls in raw form [you can use whatever language you are most comfortable with and the relevant client lib to do the same using code].

Channels are implemented as categories, the first call creates a category, passing 701 as parentId.
In your case, the ID will be different, of course. Here is what category ID 701 looks like on my ENV:

*************************** 1. row ***************************
                         id: 701
                  parent_id: 699
                      depth: 2
                 partner_id: 102
                       name: channels
                  full_name: MediaSpace>site>channels
...

You can find the right ID for your case with category->list().
Optionally, you can pass a channel description to the call if you wish, my partner ID is 102, I am not including the KS but the gist of the call looks like this:

api_v3/index.php?service=category&action=add&format=2&ignoreNull=1&category:objectType=KalturaCategory&category:parentId=701&category:name=mbp&category:description=&category:tags=&partnerId=102

Next up is setting the custom metadata for whether or not to allow comments.
metadataProfileId=31 is the ChannelComments custom metadata profile on my ENV. This is created by KMS during deployment. You can find yours with a call to service=metadata_metadataprofile&action=list, passing the name “ChannelComments” as filter, or you can go to $MEDIASPACE_URL/admin/config/tab/comments#channelCommentsProfileId and find it there.
the add() action accepts an XML, similar to the below.

api_v3/index.php?service=metadata_metadata&action=add&format=2&ignoreNull=1&metadataProfileId=31&objectType=2&objectId=884&xmlData=<metadata><AllowCommentsInChannel>true</AllowCommentsInChannel></metadata>&partnerId=102

You also need a call to add metadata to the categoryAdditionalInfo ProfileId, which in my case, is 24:

*************************** 1. row ***************************
               id: 24
       created_at: 2015-12-21 16:52:59
       updated_at: 2015-12-21 16:52:59
          version: 2
file_sync_version: 2
    views_version: 2
       partner_id: 102
             name: CategoryAdditionalInfo
      system_name: CategoryAdditionalInfo`

The call looks like this:
api_v3/index.php?service=metadata_metadata&action=add&format=2&ignoreNull=1&metadataProfileId=24&objectType=2&objectId=884&xmlData=<?xml version="1.0"?>
<metadata><Detail><Key>commentsPrivate</Key><Value/></Detail></metadata>

Then, we also need to decide about the moderation type, in my case, I chose 0, which means no moderation. If moderation is required, you can set it to 1 instead.

api_v3/index.php?service=category&action=update&format=2&ignoreNull=1&id=884&category:objectType=KalturaCategory&category:id=884&category:moderation=0&partnerId=102

And here is the resulting category/channel:

id: 884
parent_id: 701
depth: 3
partner_id: 102
name: mbp
full_name: MediaSpace>site>channels>mbp

In terms of the channel type, that’s controlled by these attributes on the category object:

    Open:
            privacy 2
            contributionPolicy      1

    Restricted:
            privacy 2
            contributionPolicy      2

    Private:
            privacy 3
            contributionPolicy      2

    Relevant enums are:
    class KalturaContributionPolicyType extends KalturaEnumBase
    class KalturaPrivacyType extends KalturaEnumBase
    {
            const ALL = 1;
            const AUTHENTICATED_USERS = 2;
            const MEMBERS_ONLY = 3;
    }

    {
            const ALL = 1;
            const MEMBERS_WITH_CONTRIBUTION_PERMISSION = 2;
    }

    class KalturaCategoryUserPermissionLevel extends KalturaEnumBase
    {
            const MANAGER = 0;
            const MODERATOR = 1;
            const CONTRIBUTOR = 2;
            const MEMBER = 3;
            const NONE = 4;
    }

The appearInList member controls whether or not the channel will appear when listing the channels.
If it’s private, it should be set to 3:

1= No Restriction(default), 3= Private

With regards to the user permissions per channel, that’s kept on the categoryUser object.

    class KalturaCategoryUserPermissionLevel extends KalturaEnumBase
    {
            const MANAGER = 0;
            const MODERATOR = 1;
            const CONTRIBUTOR = 2;
            const MEMBER = 3;
            const NONE = 4;
    }

Hope this helps,

1 Like

Hey Thanks! I’ll give it a shot and let you know how it goes.

Well I’m very glad to report that this was a huge help, which got me on the right path to manipulating the “ChannelCategories” metadata which was my ultimate goal all along.

Thanks again!

Hi James,

Great. Glad to hear it helped:)

hi Jess, I couldn’t follow your steps ):
The first error I got was adding data by the matedate service - when I input the same thing xml data - "?xml version=“1.0” I get error - "invalid metadata data: The document has no document element. at line 0."
If I remove the line the error stays the same.

And in the last call I get the error - “Current User is not entitled to update this category”.
When I am the only client, only admin and creator.
Additionally, in the last call - how do I choose moderation type? I Can’t see it.

Is there a simple way to see all the channels in a category?
Is there a way to get the channel ID by name?
Or assign a channel to a category?
Or see all channels for client? (In Category.Objects there are no channels, only categories)

Any one these tasks will be good for me, I failed to find any documentation on how it is done.
Thanks ahead, Dor.

Hi Dor,

The best place to go to for API documentation is https://developer.kaltura.com.
Under https://developer.kaltura.com/recipes, you’ll find step by step code examples for various tasks, including adding metadata: https://developer.kaltura.com/recipes/metadata#/start

As for entitlement, you can set:
privileges = “disableentitlement”;
and then pass privileges as the last parameter of the session.start() call. This will disable any entitlement enforcement.

As I said, channels are just categories with special attributes, look at the HTTP requests I posted above for examples.
If you have specific code snippets that do not work, feel free to post them.

1 Like

Hi Jess, first of all thanks for the quick replay,
I have already visited https://developer.kaltura.com, it contains no information regarding channels and/or their connection to categories,
I tried looking into matedate because you referred to it in the answer above, but in the linked documentation is just information on how to upload or download files…
Nothing regarding channels…

I need to get a list of channels, and I couldn’t find it anywhere :confused:
Its like the whole channels section is entirety different from the category’s.
Dor.

Hi Dor,

There is no specific info about channels because, as I said, channels is a KMS concept, not an API one. Channels are just categories with “special” attributes. That is, they are categories that reside under specific parent categories KMS is configured to look at and they have specific entitlement and moderation options set on them.

This URL https://developer.kaltura.com/recipes/metadata#/start will walk you through using the metadata APIs, which KMS makes vast use of, for several important functions.
Please see the calls I am referring to in my original answer to James. If there are specific questions you have or code that is not working for you, feel free to post it.

1 Like