The application takes a meta category name as an input, finds all the leaf categories under the meta and then finds item specifics for these leaf categories. The sample has been written using C# .NET. The item specifics information is outputted in the following format.
CategoryID Name Value MinValues MaxValues SelectionMode VariationSpecifics ParentName ParentValue
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eBay.Service.Call;
using eBay.Service.Core.Sdk;
using eBay.Service.Util;
using eBay.Service.Core.Soap;
namespace Merchant_OnBoarding_Trading_Samples
{
//create the context
ApiContext context = new ApiContext();
//set the User token
context.ApiCredential.eBayToken = "Your token";
//set the server url
context.SoapApiServerUrl = "https://api.ebay.com/wsapi";
//set the version
context.Version = "817";
context.Site = SiteCodeType.Germany;
GetCategoriesCall gc = new GetCategoriesCall(context);
gc.ViewAllNodes = true;
gc.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);
gc.CategoryParent = new StringCollection();
//For the sake of example, only one parent category is being added. Being a collection
//this can take more than one parent categoryIDs
gc.CategoryParent.Add("15724");
gc.Execute();
if(gc.ApiResponse.Ack == AckCodeType.Success)
{
//Store the version number so that you can compare it the next time you make a call
//and verify if the category hierarchy has been updated.
Console.WriteLine(gc.ApiResponse.Ack + " : " + gc.ApiResponse.CategoryVersion);
CategoryTypeCollection cats = gc.ApiResponse.CategoryArray;
//GetCategorySpecifics call
GetCategorySpecificsCall gcs = new GetCategorySpecificsCall(context);
gcs.CategoryIDList = new StringCollection();
foreach (CategoryType category in cats)
{
//Get ItemSpecific data for leaf categories
if (category.LeafCategory == true)
{
//initialize the category list
gcs.CategoryIDList.Add(category.CategoryID);
}
foreach (RecommendationsType recommendations in gcs.RecommendationList)
{
string catID = recommendations.CategoryID;
if (recommendations.NameRecommendation.Count == 0)
{
//Category does not have any recommendations, so just write the input info
Console.WriteLine(catID + ": Category does not have any recommendations");
}
foreach (NameRecommendationType recommendation in recommendations.NameRecommendation)
{
string name = recommendation.Name;
string parent = "";
RecommendationValidationRulesType validations = recommendation.ValidationRules;
//If VariationSpecifics is not returned in the response, .NET sets it to the default value
//Hence set to disabled and set it only if it is actually returned in the response
string variationsEnabled = "";
if (validations.VariationSpecificsSpecified)
{
variationsEnabled = validations.VariationSpecifics.ToString();
}
string validation = validations.MinValues + "\t" + validations.MaxValues + "\t"
+ validations.SelectionMode + "\t" + variationsEnabled;
//there are no values for this recommendation, so write it out at this point
if (recommendation.ValueRecommendation.Count == 0)
{
//Category does not have any recommendations, so just write the input info
Console.WriteLine(catID + "\t" + name + "\t" + validation);
}
foreach (ValueRecommendationType value in recommendation.ValueRecommendation)
{
if (value.ValidationRules != null)
{
parent = value.ValidationRules.Relationship[0].ParentName + "\t" + value.ValidationRules.Relationship[0].ParentValue + "\t";
}
Console.WriteLine(catID + "\t" + name + "\t" + value.Value + "\t" + validation + "\t" + parent);