For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

Getting all of my store categories

  • Answer ID 1296
  • Published 09/11/2008 04:40 PM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=1296
Product
How can I get all the categories for my store?

Summary  

GetStore returns the store categories hierarchically.  Since the categories can be nested very differently from level to level, you essentially need to use recursive logic to retrieve all of them.


Detailed Description  

Here is a sample C# code using the .NET SDK to retrieve all the store categories. 

using eBay.Service.Core.Sdk;
using eBay.Service.Core.Soap;
using eBay.Service.Call;
using eBay.Service.Util;

namespace NETSDKSample
{
   
public class SDKSample
   
{
       
private void GetStore()
       
{ 
            //set your credentials for the call 
           
ApiContext context = new ApiContext();
            context.ApiCredential.ApiAccount.Developer = "devID";
            
context.ApiCredential.ApiAccount.Application = "appID";
           
  context.ApiCredential.ApiAccount.Certificate = "certID";
            
context.ApiCredential.eBayToken = "token";
           
// Set the URL
           
context.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi";
           
// Set logging
           
context.ApiLogManager = new ApiLogManager();
           
context.ApiLogManager.ApiLoggerList.Add(new eBay.Service.Util.FileLogger("Messages.log", true, true, true));
           
context.ApiLogManager.EnableLogging = true;
           
// Set the version
           
context.Version = "571";
           
//create call
           
GetStoreCall call = new GetStoreCall(context);
           
//get just the store categories
           
call.CategoryStructureOnly = true;
           
call.Execute();

            //iterate through the top level categories
           
foreach (StoreCustomCategoryType cat in call.Store.CustomCategories)
           
{
               
GetChildCategories(cat);
           
}

        }

        private void GetChildCategories(StoreCustomCategoryType cat)
       
{
           
//get the category name, ID and whether it is a leaf
           
long id = cat.CategoryID;
           
string name = cat.Name;
           
bool leaf = (cat.ChildCategory.Count == 0);
           
Console.WriteLine("id = " + id + " name = " + name + " leaf= " + leaf);

            //condition to end the recursion
           
if (leaf)
           
{
               
return;
           
}

            //continue the recursion for each of the child categories
           
foreach (StoreCustomCategoryType childcat in cat.ChildCategory)
           
{
               
GetChildCategories(childcat);
           
}
       
}

    }

}



Additional Information

Documentation:  GetStore

 

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter