Hi @adeelmiraj,
Below is a full example using the PHP client [can be obtained from https://github.com/kaltura/KalturaGeneratedAPIClientsPHP/archive/v13.20.0.tar.gz].
The objectId param should be the category ID, passed as a string [for PHP specifically, it doesn’t matter since it’s not a strongly typed language]. You didn’t mention your language of choice but the same should work with all our API clients.
<?php
require_once('/path/to/KalturaClient.php');
$partnerId=;
$partnerSecret='';
$userId='';
$config = new KalturaConfiguration($partnerId);
$config->serviceUrl = 'https://www.kaltura.com';
$client = new KalturaClient($config);
$ks = $client->session->start(
$partnerSecret,
$userId,
KalturaSessionType::ADMIN,
$partnerId,
86400,
"disableentitlement");
$client->setKS($ks);
$objectType = KalturaMetadataObjectType::CATEGORY;
// create a metadata profile
$metadataPlugin = KalturaMetadataClientPlugin::get($client);
$metadataProfile = new KalturaMetadataProfile();
$metadataProfile->metadataObjectType = $objectType;
$metadataProfile->createMode = "1";
$metadataProfile->name = "z1";
$metadataProfile->systemName = "myz1";
$xsdData = "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><xsd:element name=\"metadata\"><xsd:complexType><xsd:sequence><xsd:element id=\"md_1FB651DF-20C9-BC17-60B9-6A7E93DBA671\" name=\"Myfield\" minOccurs=\"0\" maxOccurs=\"1\" type=\"textType\"><xsd:annotation><xsd:documentation></xsd:documentation><xsd:appinfo><label>myfield</label><key>myfield</key><searchable>true</searchable><timeControl>false</timeControl><description></description></xsd:appinfo></xsd:annotation></xsd:element></xsd:sequence></xsd:complexType></xsd:element><xsd:complexType name=\"textType\"><xsd:simpleContent><xsd:extension base=\"xsd:string\"></xsd:extension></xsd:simpleContent></xsd:complexType><xsd:complexType name=\"dateType\"><xsd:simpleContent><xsd:extension base=\"xsd:long\"></xsd:extension></xsd:simpleContent></xsd:complexType><xsd:complexType name=\"objectType\"><xsd:simpleContent><xsd:extension base=\"xsd:string\"></xsd:extension></xsd:simpleContent></xsd:complexType><xsd:simpleType name=\"listType\"><xsd:restriction base=\"xsd:string\"></xsd:restriction></xsd:simpleType></xsd:schema>";
$viewsData = "";
try {
$result = $metadataPlugin->metadataProfile->add($metadataProfile, $xsdData, $viewsData);
$metadataProfileId = $result->id;
$objectId = ""; //category ID as string
$xmlData = "<metadata><Myfield>LINUX RULES</Myfield></metadata>";
try {
// if created successfully, add metadata
$result = $metadataPlugin->metadata->add($metadataProfileId, $objectType, $objectId, $xmlData);
var_dump($result);
} catch (Exception $e) {
echo $e->getMessage();
}
} catch (Exception $e) {
echo $e->getMessage();
}
// retrieve metadata associated with a given category ID
$filter = new KalturaMetadataFilter();
$filter->metadataObjectTypeEqual = KalturaMetadataObjectType::CATEGORY;
$filter->objectIdEqual = ""; //category ID as string
$pager = new KalturaFilterPager();
try {
$result = $metadataPlugin->metadata->listAction($filter, $pager);
var_dump($result);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
You can learn about how to work with custom metadata by going through this tutorial:
https://developer.kaltura.com/workflows/Enrich_and_Organize_Metadata/Working_with_metadata;step=1
This tutorial explains how to work with ENTRY custom metadata objects/records whereas you’ll need to work with CATEGORY metadata but otherwise, the flow is similar and so are the service and action names [endpoints].
Each step also includes code samples.