Create a new product.

A product's attributes object is keyed by each attribute's id, so the attribute must exist before a product can reference it. An attribute's id defaults to its name in underscored form and cannot be changed afterwards.

Create a product with an attribute
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

// Create the attribute first. Its id is derived from the name,
// so this attribute is referenced as `material`.
await swell.post('/attributes', {
  name: 'Material',
  type: 'select',
  values: ['Silver', 'Gold', 'Titanium'],
  visible: true,
  filterable: true
});

// Create a product that uses it, keyed by the attribute id
await swell.post('/products', {
  name: 'Signet Ring',
  price: 149.00,
  active: true,
  attributes: {
    material: 'Silver'
  }
});

// A value can also be an array
await swell.post('/products', {
  name: 'Mixed Metal Bangle',
  price: 89.00,
  active: true,
  attributes: {
    material: ['Silver', 'Gold']
  }
});

Variant attributes are created a different way. An option with variant set to true and at least one value creates or updates the matching attribute record automatically, and fills in the product's attributes from the option values.