All Products
Search
Document Center

Media asset category

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Create a category

For more information about the request and response parameters, see AddCategory.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("AddCategory", {
    ParentId: -1, // Sets the parent category ID. If you do not set this parameter, a level-1 category is generated. The root node category ID is -1.
    CateName: 'CateName' // Sets the category name.
}, {}).then(function (response) {
    if (response.Category){
        // The information about the created category.
        console.log('ParentId = ' + response.Category.ParentId);
        console.log('CateId = ' + response.Category.CateId);
        console.log('CateName = ' + response.Category.CateName);
        console.log('Level = ' + response.Category.Level);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Modify a category

For more information about the request and response parameters, see UpdateCategory.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("UpdateCategory", {
    CateId: -1, // Sets the category ID.
    CateName: 'CateName2' // Sets the category name.
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Delete a category

For more information about the request and response parameters, see DeleteCategory.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DeleteCategory", {
    CateId: -1 // Sets the category ID.
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Query a category and its subcategories

For more information about the request and response parameters, see GetCategories.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("GetCategories", {
    CateId: -1,
    PageNo: 1,
    PageSize: 10
}, {}).then(function (response) {
    // The specified category information.
    if (response.Category){
        console.log('ParentId = ' + response.Category.ParentId);
        console.log('CateId = ' + response.Category.CateId);
        console.log('CateName = ' + response.Category.CateName);
        console.log('Level = ' + response.Category.Level);
        console.log('SubTotal = ' + response.SubTotal);
    }
    if (response.SubCategories && response.SubCategories.Category && response.SubCategories.Category.length > 0){
        for (var i=0; i<response.SubCategories.Category.length; i++){
            var subCategory = response.SubCategories.Category[i];
            console.log('SubCategories.ParentId = ' + subCategory.ParentId);
            console.log('SubCategories.CateId = ' + subCategory.CateId);
            console.log('SubCategories.CateName = ' + subCategory.CateName);
            console.log('SubCategories.Level = ' + subCategory.Level);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});