03-03-2023 12:48 PM
Hi there,
I am trying to filter a search by top level/parent category, I have no idea how to go about this but I figured GetCategories would be a start only it isn't returning any results. Are there any samples (in PHP) to demonstrate the usage so I can try to see where I am going wrong?
Many thanks!
03-03-2023 01:22 PM
I believe the taxonomy rest api is preferable for that information as several other category related calls suggest moving to it. It also has getCategorySubtree which you could use in subsequence to climb the tree.
For the calls that give everything:
Traditional trading api:
<?php
$iaftoken = "";
$url = "https://api.sandbox.ebay.com/ws/api.dll";
$clientid = "";
$clientsecret = "";
$devid = "";
$call = "GetCategories";
$siteid = "0";
$version = "1295";
$header=array(
"X-EBAY-API-IAF-TOKEN:$iaftoken",
"X-EBAY-API-COMPATIBILITY-LEVEL:$version",
"X-EBAY-API-DEV-NAME:$devid",
"X-EBAY-API-APP-NAME:$clientid",
"X-EBAY-API-CERT-NAME:$clientsecret",
"X-EBAY-API-SITEID:$siteid",
"X-EBAY-API-CALL-NAME:$call",
"Content-Type:text/xml"
);
$data="
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<GetCategoriesRequest xmlns=\"urn
apis:eBLBaseComponents\">
<DetailLevel>ReturnAll</DetailLevel>
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<ViewAllNodes>true</ViewAllNodes>
</GetCategoriesRequest>
";
echo "\nphp structure:\n";
print_r($data);
echo "\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
echo "\nBefore Call:\n";
print_r(curl_getinfo($ch));
echo "\n";
$result = curl_exec($ch);
curl_close($ch);
echo "\nAfter Call:\n";
print_r(curl_getinfo($ch));
echo "\n";
echo "\nResult:\n";
print_r($result);
echo "\n";
?>
REST taxonomy api:
<?php
$iaftoken = "";
$marketplace_id = "0";
$url = "https://api.sandbox.ebay.com/commerce/taxonomy/v1/category_tree/$marketplace_id";
$header=array(
"Authorization: Bearer $iaftoken",
"Accept: application/json",
"Content-Type: application/json"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
echo "\nBefore Call:\n";
print_r(curl_getinfo($ch));
echo "\n";
$result = curl_exec($ch);
curl_close($ch);
echo "\nAfter Call:\n";
print_r(curl_getinfo($ch));
echo "\n";
echo "\nResult:\n";
print_r($result);
echo "\n";
?>
03-03-2023 01:52 PM
That looks absolutely brilliant thank you! I'll have a go at it tomorrow, I really appreciate your reply!
Thanks!