Skip to main content
Published: August 22 2006, 1:37:00 PMUpdated: July 26 2022, 1:19:52 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>2022-07-26T20:15:03.911Z</Timestamp>
<Ack>Success</Ack>
<Version>1173</Version>
<Build>E1173_CORE_API5_19110890_R1</Build>
<SuggestedCategoryArray>
<SuggestedCategory>
<Category>
<CategoryID>73839</CategoryID>
<CategoryName>iPods &amp; MP3 Players</CategoryName>
<CategoryParentID>293</CategoryParentID>
<CategoryParentID>15052</CategoryParentID>
<CategoryParentName>Consumer Electronics</CategoryParentName>
<CategoryParentName>Portable Audio &amp; Headphones</CategoryParentName>
</Category>
<PercentItemFound>77</PercentItemFound>
</SuggestedCategory>

    ........
  </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 Version465
.NET SDK Version.NET SDK v465.0 full release

 



Additional Resources

 

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

Got thoughts? Click the feedback button – your insights help us improve!