Full Category Name from the GetSuggestedCategories response
Find the answer to your question
Advanced Search
Products
Question
How can I get the CategoryFullName from the response of GetSuggestedCategories?
Answer
Summary
GetCategories returns the leaf level category and all the parent categories in the Category node. What you need to do is to concatenate each of the Parents starting from the First CategoryParentName and then concatenate the leaf.
Detailed Description
Consider this response from GetSuggestedCategories:
........
</SuggestedCategoryArray>
<CategoryCount>10</CategoryCount>
</GetSuggestedCategoriesResponse>
For the First Category, you start with the First CategoryParent Consumer Electronics, concatenate MP3 Players & Accessories, MP3 Players and finally the leaf Category Other MP3 Players, in that order to get the following Category Full Name:
Consumer Electronics:MP3 Players & Accessories:MP3 Players: Other MP3 Players
Here is a sample C# code that uses the SDK to create the Category full name:
using System;
using eBay.Service.Call;
using eBay.Service.Core.Sdk;
using eBay.Service.Util;
using eBay.Service.Core.Soap;
namespace SDK3Sample
{
public void GetCategoryFullName()
{
GetSuggestedCategoriesCall apicall = new GetSuggestedCategoriesCall(GetContext());
apicall.Query = "MP3 Players";
apicall.Execute();
//Check if a SuggestedCategoryList is returned by the call
if (apicall.SuggestedCategoryList != null)
{
int iCategoryCount = apicall.SuggestedCategoryList.Count;
if (iCategoryCount > 0)
{
for (int i=0; i< iCategoryCount; i++)
{
//Process other elements
string strFullName = "";
//Get the Category Full Name
int iParentCount = apicall.SuggestedCategoryList[i].Category.CategoryParentName.Count;
if (iParentCount > 0)
{
for (int j = 0; j < iParentCount; j++)
{
strFullName = strFullName + apicall.SuggestedCategoryList[i].Category.CategoryParentName[j] + ":";
}
strFullName = strFullName + apicall.SuggestedCategoryList[i].Category.CategoryName;
//Store the Category Full Name
}
}
}
}
}
public ApiContext GetContext()
{
context = new ApiContext();
//set the your credentials
context.ApiCredential.eBayToken = "token";
context.SoapApiServerUrl = "url";
//set the version
context.Version = "1131";
//set the logging
string logFile = "LogFile.txt";
context.ApiLogManager = new ApiLogManager();
context.ApiLogManager.ApiLoggerList.Add(new FileLogger(logFile, true, true, true));
context.ApiLogManager.EnableLogging = true;
return context;
}
}
Version Info
The code example above was based on the versions specified below:
| API Schema Version | 465 |
| .NET SDK Version | .NET SDK v465.0 full release |
Additional Resources
- Documentation for GetSuggestedCategories