Best practices for GetCategories API call
All metadata calls and GetCategories in particular, have a significantly large response size when retrieved in full. Here are some suggestions to
optimize the usage and increase the efficiency of your application:
- Set up an admin function to run on a scheduled basis. Make a call to GetCategories for the first time with DetailLevel ReturnAll, download the entire structure and store it in your database. Once you have that, make a call everyday with no DetailLevel and get just the CategoryVersion. Compare this with the CategoryVersion in your database. If there is a change, then make a call to GetCategories with DetailLevel ReturnAll and get the new structure.
- Use compression. If you use the .NET or the Java SDK, compression is turned on by default. If you use other technologies, see this KB article: Implementing Compression: When and How.
- Inspite of compression, if you run into time issues when you try to get the entire structure, use LevelLimit to first get the top level categories. Then for each of the top level categories, set it as the CategoryParent and get the hierarchy below them. This mechanism is also very useful if you list in a few verticals and you can get just those branches of interest.
Sample GetCategories XML request to get the top level categories:
Sample GetCategories XML request to get the hierarchy for a top level
If you already have items listed with an old category, and if there is a change, where category is mapped to new CategoryID, a quick way to find the mappings
is to call GetCategoryMappings.