Modules

Product Variants

Sizes, colors and other attributes of a model product. Each variant is a product.

Overview

The company defines attributes (Size, Color...) and their values. A model product gets its variants by combining values: each variant is a product of its own (itm_...) with its code, barcode, price and stock, so it is sold, invoiced and moved like any product. Its name is the model plus the values, for example Polo · M · Black.

Requires the Product variants module. An owner or admin turns it on in Settings > Modules. While it is off, every endpoint on this page returns 403 with type permission_error and code module_disabled.

Endpoints

MethodPathPermissionDescription
GET/v1/variant-attributesreadAttributes with their values
POST/v1/variant-attributeswriteCreate an attribute (name, kind: text or color)
POST/v1/variant-attributes/{id}/valueswriteAdd a value (name, code, color_hex)
GET/v1/products/{id}/variantsreadVariants of a model with their stock; variant_of when the product is a variant
POST/v1/products/{id}/variantswriteGenerate the missing combinations

Generate Variants

Bash
1curl -X POST "https://api.corebill.io/v1/products/itm_polo/variants" \
2 -H "Authorization: Bearer sk_live_your_api_key" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "values": { "vatt_size": ["vav_s", "vav_m", "vav_l"], "vatt_color": ["vav_black", "vav_white"] },
6 "code_template": "POL-001-{size}-{color}",
7 "unit_price": 49
8 }'
TypeScript
1const result = await corebill.products.generateVariants('itm_polo', {
2 values: { vatt_size: ['vav_s', 'vav_m', 'vav_l'], vatt_color: ['vav_black', 'vav_white'] },
3 code_template: 'POL-001-{size}-{color}',
4})
5console.log(result.created, result.skipped)
6const { variants } = await corebill.products.listVariants('itm_polo')
  • {size} and {color} are the attribute names; each one is replaced by the value code
  • Combinations that already exist are skipped (skipped); up to 300 per call
  • New variants copy the unit, currency, tax, cost, category and brand of the model, and start with zero stock
  • Once a model has variants, new ones must use the same attributes