Question:

Is there any way to import bunch of new products using OData API in Sitecore Commerce 9?

Matthew: 20 May 2022

I found that there are no OData API methods for importing new products into the catalog of Sitecore Commerce 9. The only thing you can do is to use /api/DoUxAction() to add new sellable item and then associate this sellable item with inventory. But the JSON object being sent is too big and doesn't seem to be appropriate to import a big set of products.

Is there any way to import bunch of new products to the catalog via OData API in efficient manner?

Thanks.

Answer:
Isaac: 20 May 2022

tl;dr There are import APIs for both catalogs and inventory sets, but they are designed around importing data that was exported from another Commerce Engine installation. Custom imports could be massaged to match the expected format, but it's probably not worth it.

Importing Catalogs

The ImportCatalog() OData API might do what you need, but the archive file it accepts has very specific contents.

If want to create items from a custom CSV or other source, you're better off creating your own Commerce plugin that exposes a Controller / Command.

Read on for a breakdown of the ImportCatalog() API.

ImportCatalog() accepts:

  1. A zip file via the importFile parameter, the structure of which is defined below
  2. A mode string parameter - if that parameter is "replace", all catalog data will be deleted before the import starts. If mode is anything else, entities will be replaced by their ID.

The expected structure of the file is JSON files of serialized Commerce entities, complete with $type attribution and embedded components.

For most entities, the expected filename is EntityName.*.json (eg. SellableItem.1.json). Entities of this format that will be imported are:

  • RelationshipDefinition.*.json
  • LocalizationEntity.*.json
  • Catalog.*.json
  • Category.*.json
  • SellableItem.*.json

In that order.

Relationships are imported from any zip entries in the Relationships/ folder. Each file is expected to be a serialized List<RelationshipArgument> (from the catalog plugin).

Importing Inventory

Inventory can be imported using ImportInventorySets(), which accepts the same parameters. Entities from it's zip are processed in this order:

  • LocalizationEntity.*.json
  • InventorySet.*.json
  • InventoryInformation.*.json
  • Relationship/*.json (InventorySet -> InventoryInformation)