# createProduct

## Overview

Creates a new product record with a unique code and required unit-of-measure reference. Optionally assigns categories and attribute values in the same operation.

## Modules Commands Used

- `product-management.CreateProduct` — validates uniqueness of product code and persists the new product in draft status
- `product-management.AssignProductToCategory` — assigns each specified category to the newly created product
- `product-management.AssignAttributeValueToProduct` — assigns each specified attribute value to the newly created product

## Exception Handling

| Error Code | Source | Description |
| --- | --- | --- |
| DUPLICATE_CODE | CreateProduct | A product with the given code already exists |
| MISSING_REQUIRED_FIELD | CreateProduct | A required field such as name or unit of measure was not provided |
| INVALID_UOM | CreateProduct | The specified unit of measure does not exist |
| CATEGORY_NOT_FOUND | AssignProductToCategory | A specified category does not exist |
| PRODUCT_NOT_FOUND | AssignProductToCategory / AssignAttributeValueToProduct | The just-created product was not found (internal) |
| ATTRIBUTE_NOT_FOUND | AssignAttributeValueToProduct | A specified attribute does not exist |
| PRODUCT_ARCHIVED | AssignAttributeValueToProduct | The product is archived and cannot accept assignments (internal) |
| AXIS_STRUCTURE_LOCKED | AssignAttributeValueToProduct | The attribute axis structure is locked |
| INVALID_VALUE | AssignAttributeValueToProduct | The attribute value is invalid for the specified attribute |
