Skip to content

Commerce Catalog API Reference

advanced
📜Corecommerce

The Catalog API provides programmatic access to catalog structures including catalogs, categories (nodes), products (entries), and variants. The primary entry points are ICatalogSystem, IContentRepository, and ReferenceConverter.

Optimizely.Commerce.Catalog

InterfacePurpose
ICatalogSystemLow-level catalog operations (legacy)
IContentRepositoryContent-based catalog CRUD (recommended)
ReferenceConverterConverts between catalog entry codes and ContentReference
IRelationRepositoryManages parent-child and variant relationships
ICatalogImportExportBulk import/export operations

Converts between catalog entry/node codes and CMS content references.

MethodReturnsDescription
GetContentLink(string code)ContentReferenceResolves a catalog code to a content reference
GetContentLink(int entryId, CatalogContentType)ContentReferenceResolves by entry ID and type
GetCode(ContentReference)stringReturns the catalog code for a content reference
TypeBase classDescription
ProductProductContentTop-level purchasable item with variants
VariationVariationContentSpecific SKU with price and inventory
PackagePackageContentBundle of entries sold as one SKU
BundleBundleContentCollection of entries sold individually

Loads a single catalog entry or node.

Parameters

NameTypeDescription
contentLinkContentReferenceReference to the catalog content

Returns: T where T is a catalog content type

Throws: ContentNotFoundException if the reference does not exist

Load a product by code
csharp
public class CatalogService
{
  private readonly IContentRepository _contentRepo;
  private readonly ReferenceConverter _referenceConverter;

  public CatalogService(
      IContentRepository contentRepo,
      ReferenceConverter referenceConverter)
  {
      _contentRepo = contentRepo;
      _referenceConverter = referenceConverter;
  }

  public ProductContent GetProduct(string code)
  {
      var contentLink = _referenceConverter.GetContentLink(code);
      return _contentRepo.Get<ProductContent>(contentLink);
  }
}

Returns immediate children of a catalog node.

Parameters

NameTypeDescription
parentLinkContentReferenceReference to the parent node or catalog

Returns: IEnumerable&lt;T&gt;

List products in a category
csharp
var categoryRef = _referenceConverter.GetContentLink("tops-category");
var products = _contentRepo.GetChildren<ProductContent>(categoryRef);

foreach (var product in products)
{
  Console.WriteLine($"{product.Code}: {product.DisplayName}");
}

Creates a new default instance under a parent node.

Parameters

NameTypeDescription
parentLinkContentReferenceParent node or catalog root

Returns: T — writable content instance

Persists catalog content to the database.

Parameters

NameTypeDescription
contentIContentThe catalog content to save
actionSaveActionPublish, CheckIn, Save
accessAccessLevelAccess level check; use AccessLevel.NoAccess to skip

Returns: ContentReference

Create a new product
csharp
var categoryRef = _referenceConverter.GetContentLink("tops-category");
var product = _contentRepo.GetDefault<FashionProduct>(categoryRef);
product.Code = "SHIRT-001";
product.DisplayName = "Classic Oxford Shirt";
product.Name = "Classic Oxford Shirt";
_contentRepo.Save(product, SaveAction.Publish, AccessLevel.NoAccess);

Manages product-to-variant and bundle relationships.

MethodReturnsDescription
GetRelationsBySource<T>(ContentReference)IEnumerable&lt;T&gt;Gets relations where this entry is the source
GetRelationsByTarget<T>(ContentReference)IEnumerable&lt;T&gt;Gets relations where this entry is the target
UpdateRelation(ContentRelation)voidAdds or updates a relation
RemoveRelation(ContentRelation)voidRemoves a relation
Get variants for a product
csharp
public IEnumerable<VariationContent> GetVariants(ContentReference productLink)
{
  var relations = _relationRepo
      .GetRelationsBySource<ProductVariation>(productLink);

  return relations
      .Select(r => _contentRepo.Get<VariationContent>(r.Target));
}
NameTypeDescription
contentLinkContentReferenceReference to catalog content
forceDeletebooltrue = permanent delete, false = soft delete

Throws: AccessDeniedException if the user lacks delete permissions

ExceptionCause
ContentNotFoundExceptionContent reference does not resolve
AccessDeniedExceptionInsufficient permissions for the operation
ValidationExceptionRequired fields missing or code already exists
CatalogCodeAlreadyExistsExceptionDuplicate catalog entry code