ItemCategories API

Retrieve category information from the category hierarchy. Get category details including name and full path from root category.

Overview

Core Concept

The ItemCategories object provides methods for retrieving category information from the category hierarchy. Categories are organized in a tree structure with categories at the top level and attribute groups (subcategories) beneath them.

Category vs Attribute Group: In the hierarchy, a category (categoryId) represents a top-level category like "Services" or "Materials". An attribute group (attributeGroupId) represents a subcategory within a category, such as "General Labor" under "Services".

Hierarchy Example

Home Improvement (category)
├── Flooring (category)
│   ├── Hardwood (category)
│   │   ├── Oak Varieties (attributeGroup)
│   │   └── Maple Varieties (attributeGroup)
│   └── Laminate (category)
│       └── Budget Options (attributeGroup)
└── Services (category)
    ├── General Labor (attributeGroup)
    └── Specialized Labor (attributeGroup)

ItemCategories.get(categoryId, attributeGroupId)

Method

Retrieves a category by categoryId and optional attributeGroupId. Returns the category details including name and the full path from root category to the attribute group.

Parameters

ParameterTypeRequiredDescription
categoryId number Yes The category ID to retrieve
attributeGroupId number No The attribute group ID. If provided, must belong to the specified category.

Returns

Returns an object with category details, or null if not found.

PropertyTypeDescription
categoryId number The category ID
attributeGroupId number|null The attribute group ID, or null if only categoryId was provided
name string The display name of the category or attribute group
path string[] Array of names from root category to this attribute group

Examples

// Get category only (no attributeGroupId)
var category = ItemCategories.get(100);
if (category) {
  console.log('Name: ' + category.name);
  console.log('Path: ' + category.path.join(' > '));
  // Output: "Services > Labor"
}

// Get attribute group with categoryId and attributeGroupId
var category = ItemCategories.get(100, 200);
if (category) {
  console.log('Category ID: ' + category.categoryId);
  console.log('Attribute Group ID: ' + category.attributeGroupId);
  console.log('Name: ' + category.name);
  console.log('Path: ' + category.path.join(' > '));
  // Output: "Services > Labor > General Labor"
}

// Handle not found
var category = ItemCategories.get(999999);
if (!category) {
  console.log('Category not found');
}
Returns null when:
  • The categoryId does not exist or is deleted
  • The attributeGroupId does not exist or is not visible
  • The attributeGroupId does not belong to the specified categoryId

Practical Examples

Code Examples

Display Category Breadcrumb

// Get an item and display its category path
var item = Items.get(12345);
if (item && item.attributeGroupId) {
  var category = ItemCategories.get(item.categoryId, item.attributeGroupId);
  if (category) {
    template.categoryDisplay.value = category.path.join(' > ');
    // Output: "Home Improvement > Flooring > Hardwood > Oak Varieties"
  }
}

Build Category Tree Navigation

// Navigate through the category hierarchy
function displayLevel(parentId) {
  var results = ItemCategories.search({ parentId: parentId });

  console.log('--- Level: ' + (parentId || 'Root') + ' ---');
  for (var i = 0; i < results.items.length; i++) {
    var item = results.items[i];
    if (item.type === 'category') {
      console.log('[Category] ' + item.name + ' (ID: ' + item.categoryId + ')');
    } else {
      console.log('[Attribute Group] ' + item.name + ' (ID: ' + item.id + ')');
    }
  }
}

// Display root level
displayLevel(null);

// Display children of category 100
displayLevel(100);

Find Items in a Category

// Get category info for filtering
var category = ItemCategories.get(100, 200);
if (category) {
  console.log('Looking for items in: ' + category.name);
  console.log('Full path: ' + category.path.join(' > '));

  // Search for items in this category
  var items = Items.search(category.name);
  console.log('Found ' + items.length + ' items');
}

Use with Items API

// Get item details including category
var item = Items.get(12345);
if (item) {
  console.log('Item: ' + item.name);
  console.log('Price: $' + item.price);

  // Display category info
  if (item.categoryId) {
    console.log('Category ID: ' + item.categoryId);
    console.log('Attribute Group ID: ' + item.attributeGroupId);
    console.log('Category Path: ' + item.categoryPath.join(' > '));
  } else {
    console.log('No category assigned');
  }
}