Skip to main content
Published: August 22 2006, 1:37:00 PMUpdated: November 28 2020, 2:27:53 PM

How can I get the CategoryFullName from the response of GetSuggestedCategories?


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:
<?xml version="1.0" encoding="utf-8"?>
<GetSuggestedCategoriesResponse xmlns="urn:ebay:apis:eBLBaseComponents">
  <Timestamp>20060822T20:05:00.606Z</Timestamp>
  <Ack>Success</Ack>
  <Version>473</Version>
  <Build>e473_core_Bundled_3352783_R1</Build>
  <SuggestedCategoryArray>
    <SuggestedCategory>
      <Category>
        <CategoryID>73839</CategoryID>
        <CategoryName>Other MP3 Players</CategoryName>
        <CategoryParentID>293</CategoryParentID>
        <CategoryParentID>97927</CategoryParentID>
        <CategoryParentID>15057</CategoryParentID>
        <CategoryParentName>Consumer Electronics</CategoryParentName>
        <CategoryParentName>MP3 Players & Accessories</CategoryParentName>
        <CategoryParentName>MP3 Players</CategoryParentName>
      </Category>
      <PercentItemFound>71</PercentItemFound>
    </SuggestedCategory>
    ........
  </SuggestedCategoryArray>
<CategoryCount>8</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.ApiCredential.ApiAccount.Application = "AppID";
        context.ApiCredential.ApiAccount.Developer = "DevID";
        context.ApiCredential.ApiAccount.Certificate = "CertID";
        context.SoapApiServerUrl = "url";

        //set the version
        context.Version = "465";

        //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

How well did this answer your question?
Answers others found helpful