Manual configuration
A step-by-step guide on how to set up an organization from scratch, using our CLI
To begin receiving orders and making sales through Commerce Layer, you need to configure your organization to meet some requirements: the manual configuration involves creating all the necessary resources, linking them based on their mutual relationships, and properly populating your environment with sample (or real) data. This guide will walk you through the process of setting up a new organization using the command line from start to finish and is a good opportunity to learn (by doing) how Commerce Layer works, in deep.
Please refer to Commerce Layer data model documentation to get an overview of the most relevant API entities, their mutual relationships, and common usage with the help of E-R diagrams.
As an alternative, if you want to go straight to the chase, you can follow the short onboarding tutorial you'll be prompted as soon as you sign up to create a new organization, seed it with test data, and place your first order from scratch, in minutes.
- 1.
- 3.
- 4.
- 5.
- 6.
- Markets
- Shipping
- Payments
- Products
- 7.
- 8.
- 10.
These are the steps you need to follow to create an organization on Commerce Layer:
- 1.
- 2.Upon successful signup, skip the onboarding tutorial for the purposes of this guide (you will set up and seed the organization manually through the CLI shortly).
- 3.Click on your current organization name in the left upper corner of your dashboard homepage to access your list of organizations and then on the Add new button to create a new one for your business and enter a name on the following page as seen in the screenshots below.



If — for whatever reason — you need to delete one or more of the organizations you created, please ask the organization owner to reach out to our support team and send a specific request to [email protected] specifying the list of the organization slug you want to be deleted.
Follow these steps to create a new integration application from the dashboard (give it an Admin role) and get the related API credentials (client ID, client secret, and base endpoint). Remember to save them as we'll use them later to interact with the CLI.
Run the command below on your terminal to install the CLI using your favorite package manager:
npm install -g @commercelayer/cli
yarn global add @commercelayer/cli
Installing the CLI provides access to the
commercelayer
command, which can also be accessed with the aliases clayer
and cl
.You can run
commercelayer help
at any point to learn about the available command options.cl applications:login -o <organizationSlug> -i <clientId> -s <clientSecret> -a <applicationAlias>
Here’s a breakdown of each of the command options:
- The
applications:login
command lets you manage the login with the CLI using your API credentials. - The
-o
flag allows you to pass in an organization slug as a parameter. <organizationSlug>
represents the slug from your organization’s base endpoint (e.g.sample-shop
fromhttps://sample-shop.commercelayer.io
).- The
-i
flag allows you to pass in a client ID as a parameter. <clientId>
represents your application's client ID (you can find it on the application's details page on the dashboard).- The
-s
flag allows you to pass in a client secret as a parameter. <clientSecret>
represents your application's client secret (you can find it on the application's details page on the dashboard).- The
-a
flag allows you to pass in an alias that will be associated with the credentials you want to log with on your terminal (this is useful when switching between multiple applications with different API credentials).
To get started, you need to install the resources plugin so that you can execute CRUD operations on the API resources. To do that, use the command below:
cl plugins:install resources
You can run the command
cl resources
to list all the available Commerce Layer API resources and a link to the documentation of each one. Use commercelayer resources --help
to see the available commands and what they do.For this guide, we would be using:
- The
commercelayer resources:create [RESOURCE]
command to create new resources. - The
-r, --relationship=<value>
flag which defines a relationship with another resource(s). - The
-a, --attribute=<value>
flag which defines the attributes of a resource that will be used.
To get your organization ready to receive orders, you need to create some resources. These resources are grouped into Markets, Shipping, Payments, and Products. The sections below describe each of these resources in sequential order, and how to create them using the previously installed resources plugin of the CLI. All the resources will be created using sample data, and we will add the following for each of them:
- The command for creating the resource.
- The output response of the successfully run command.
- A link to the related data model where you can check the flowchart that illustrates how the specific resource relates to other API entities.
When you successfully create a new resource, you can confirm this by running
cl resources:list <resource_type>
and checking if the resource is in the returned list (e.g. cl resources:list payment_gateways
will list all the payment gateways that have been created).The address resource is the foundation of users and merchants in Commerce Layer. It includes the literal details of a physical address of a person. An address can be associated with other resources or orders as their shipping or billing addresses.
CLI command
Response
The following command creates a new address:
cl resources:create address -a \
business="true" \
company="Sample Shop SRL" \
line_1="Via Roma 123" \
city="Firenze" \
zip_code="50123" \
state_code="FI" \
country_code="IT" \
phone="+39 055 1234567890" \
email="[email protected]"
On successful run, the newly created address object information is prompted:
{
id: 'dqJkunqnQa',
type: 'addresses',
business: true,
first_name: null,
last_name: null,
company: 'Sample Shop SRL',
full_name: 'Sample Shop SRL',
line_1: 'Via Roma 123',
line_2: null,
city: 'Firenze',
zip_code: '50123',
state_code: 'FI',
country_code: 'IT',
phone: '+39 055 1234567890',
full_address: 'Via Roma 123, 50123 Firenze FI (IT) +39 055 1234567890',
name: 'Sample Shop SRL, Via Roma 123, 50123 Firenze FI (IT) +39 055 1234567890',
email: '[email protected]',
notes: null,
lat: null,
lng: null,
is_localized: false,
is_geocoded: false,
provider_name: null,
map_url: null,
static_map_url: null,
billing_info: null,
created_at: '2022-03-17T14:27:26.526Z',
updated_at: '2022-03-17T14:27:26.526Z',
reference: null,
reference_origin: null,
metadata: {}
}
A merchant is a fiscal representative that is selling in a specific market. Tax calculators use the merchant's address to determine the tax rate for an order. The merchant needs to be associated with a billing address. To do that we will use the ID from the previously created address resource.
CLI command
Response
The following command creates a new merchant and associates it with a billing address:
cl resources:create merchants -a \
name="Sample Shop Manager" -r \
address="dqJkunqnQa"
On successful run, the newly created merchant object information is prompted:
{
id: 'qnzZLHrgmn',
type: 'merchants',
name: 'Sample Shop Manager',
created_at: '2022-03-17T14:28:27.008Z',
updated_at: '2022-03-17T14:28:27.008Z',
reference: null,
reference_origin: null,
metadata: {},
address: {
id: 'dqJkunqnQa',
type: 'addresses',
business: true,
first_name: null,
last_name: null,
company: 'Sample Shop SRL',
full_name: 'Sample Shop SRL',
line_1: 'Via Roma 123',
line_2: null,
city: 'Firenze',
zip_code: '50123',
state_code: 'FI',
country_code: 'IT',
phone: '+39 055 1234567890',
full_address: 'Via Roma 123, 50123 Firenze FI (IT) +39 055 1234567890',
name: 'Sample Shop SRL, Via Roma 123, 50123 Firenze FI (IT) +39 055 1234567890',
email: '[email protected]',
notes: null,
lat: null,
lng: null,
is_localized: false,
is_geocoded: false,
provider_name: null,
map_url: null,
static_map_url: null,
billing_info: null,
created_at: '2022-03-17T14:27:26.526Z',
updated_at: '2022-03-17T14:27:26.526Z',
reference: null,
reference_origin: null,
metadata: {}
}
}
​Stock locations contain the inventory of the SKUs (stock items) that are to be sold. A new stock location needs to be associated with an address. If the address is different from the merchant's one, then you should create a new address following the same method above and use the new address ID here. To keep it simple, we’ll use the merchant’s address.
CLI command
Response
The following command creates a new stock location and associates it with an address:
cl resources:create stock_locations -a \
name="Europe Warehouse" -r \
address="dqJkunqnQa"
On successful run, the newly created stock location object information is prompted:
{
id: 'okdYzuXRDM',
type: 'stock_locations',
number: 8207,
name: 'Europe Warehouse',
label_format: 'PDF',
suppress_etd: null,
created_at: '2022-03-17T14:29:43.763Z',
updated_at: '2022-03-17T14:29:43.763Z',
reference: null,
reference_origin: null,
metadata: {},
address: {
id: 'dqJkunqnQa',
type: 'addresses',
business: true,
first_name: null,
last_name: null,
company: 'Sample Shop SRL',
full_name: 'Sample Shop SRL',
line_1: 'Via Roma 123',
line_2: null,
city: 'Firenze',
zip_code: '50123',
state_code: 'FI',
country_code: 'IT',
phone: '+39 055 1234567890',
full_address: 'Via Roma 123, 50123 Firenze FI (IT) +39 055 1234567890',
name: 'Sample Shop SRL, Via Roma 123, 50123 Firenze FI (IT) +39 055 1234567890',
email: '[email protected]',
notes: null,
lat: null,
lng: null,
is_localized: false,
is_geocoded: false,
provider_name: null,
map_url: null,
static_map_url: null,
billing_info: null,
created_at: '2022-03-17T14:27:26.526Z',
updated_at: '2022-03-17T14:27:26.526Z',
reference: null,
reference_origin: null,
metadata: {}
}
}
An inventory model defines a list of stock locations ordered by priority. The priority determines how the availability of SKUs gets calculated within a market. If an order contains line items from two or more stock locations, the order can be split into two or more shipments, according to the selected inventory strategy.
CLI command
Response
The following command creates a new inventory model:
cl resources:create inventory_models -a name="EUR Inventory"
On successful run, the newly created inventory model object information is prompted:
{
id: 'kZXEvSYlra',
type: 'inventory_models',
name: 'EUR Inventory',
strategy: 'split_shipments',
stock_locations_cutoff: 2,
created_at: '2022-03-17T14:32:17.869Z',
updated_at: '2022-03-17T14:32:17.869Z',
reference: null,
reference_origin: null,
metadata: {}
}
​Inventory stock locations build a hierarchy of stock locations within an inventory model. In cases where an SKU is available in more stock locations, it gets shipped from the one with the highest priority. You can decide to put the associated shipments on hold if fulfilled from a specific stock location (false by default). This is useful to manage use cases like back-orders, pre-orders, or personalized orders that need to be customized before being fulfilled. To create a new inventory stock location, you need to associate it with a stock location and an inventory model. We will use the ones we created earlier.
CLI command
Response
The following command creates a new inventory stock location and associates it with a stock location and an inventory model:
cl resources:create inventory_stock_locations -r \
inventory_model="kZXEvSYlra" \
stock_location="okdYzuXRDM" -a \
priority="4"
On successful run, the newly created inventory stock location object information is prompted:
{
id: 'aWDOVSOBzj',
type: 'inventory_stock_locations',
priority: 4,
on_hold: false,
created_at: '2022-03-17T14:33:20.771Z',
updated_at: '2022-03-17T14:33:20.771Z',
reference: null,
reference_origin: null,
metadata: {},
stock_location: {
id: 'okdYzuXRDM',
type: 'stock_locations',
number: 8207,
name: 'Europe Warehouse',
label_format: 'PDF',
suppress_etd: null,
created_at: '2022-03-17T14:29:43.763Z',
updated_at: '2022-03-17T14:29:43.763Z',
reference: null,
reference_origin: null,
metadata: {}
},
inventory_model: {
id: 'kZXEvSYlra',
type: 'inventory_models',
name: 'EUR Inventory',
strategy: 'split_shipments',
stock_locations_cutoff: 2,
created_at: '2022-03-17T14:32:17.869Z',
updated_at: '2022-03-17T14:32:17.869Z',
reference: null,
reference_origin: null,
metadata: {}
}
}
​Price lists determine the SKU prices and their currency within a market. When you create a price list you have to specify the related currency and you can decide whether the associated prices include taxes or not (by default taxes are included).
CLI command
Response
The following command creates a new price list associated with the European currency, with tax included (default):
cl resources:create price_lists -a \
name="Euros Price List" \
currency_code="EUR"
On successful run, the newly created price list object information is prompted. You can see that the taxes have been included by default:
{
id: 'dlwQyCXnqB',
type: 'price_lists',
name: 'Euros Price List',
currency_code: 'EUR',
tax_included: true,
created_at: '2022-03-17T14:37:44.720Z',
updated_at: '2022-03-17T14:37:44.720Z',
reference: null,
reference_origin: null,
metadata: {}
}
A market is an aggregation of business rules, often determined by a geographical region where merchants can sell items and customers can purchase. An organization may have one or more markets associated with a merchant, inventory model, SKUs, price lists, stock items, customer groups, and more. When you create a new market you need at least to associate it with a merchant, an inventory model, and a price list. We will use the ones we created earlier.
CLI command
Response
The following command creates a new market and associate it list associates it with a merchant, an inventory model, and a price list:
cl resources:create markets -r \
merchant="qnzZLHrgmn" \
inventory_model="kZXEvSYlra" \
price_list="dlwQyCXnqB" -a \
name="Europe"
On successful run, the newly created market object information is prompted:
{
id: 'BjydJhAPko',
type: 'markets',
number: 9656,
name: 'Europe',
facebook_pixel_id: null,
checkout_url: null,
external_prices_url: null,
private: false,
created_at: '2022-03-17T14:39:47.525Z',
updated_at: '2022-03-17T14:39:47.525Z',
reference: null,
reference_origin: null,
metadata: {},
merchant: {
id: 'qnzZLHrgmn',
type: 'merchants',
name: 'Sample Shop Manager',
created_at: '2022-03-17T14:28:27.008Z',
updated_at: '2022-03-17T14:28:27.008Z',
reference: null,
reference_origin: null,
metadata: {}
},
price_list: {
id: 'dlwQyCXnqB',
type: 'price_lists',
name: 'Euros Price List',
currency_code: 'EUR',
tax_included: true,
created_at: '2022-03-17T14:37:44.720Z',
updated_at: '2022-03-17T14:37:44.720Z',
reference: null,
reference_origin: null,
metadata: {}
},
inventory_model: {
id: 'kZXEvSYlra',
type: 'inventory_models',
name: 'EUR Inventory',
strategy: 'split_shipments',
stock_locations_cutoff: 2,
created_at: '2022-03-17T14:32:17.869Z',
updated_at: '2022-03-17T14:32:17.869Z',
reference: null,
reference_origin: null,
metadata: {}
}
}
​Shipping categories determine which shipping methods are available for the associated SKUs. With this, an order will be split into multiple shipments if it contains line items belonging to more than one shipping category.
CLI command
Response
The following command creates a new shipping category:
cl resources:create shipping_categories -a name="Demo Shipping Category"
On successful run, the newly created shipping category object information is prompted:
{
id: 'MWjgYFbYVK',
type: 'shipping_categories',
name: 'Demo Shipping Category',
created_at: '2022-03-17T14:41:06.380Z',
updated_at: '2022-03-17T14:41:06.380Z',
reference: null,
reference_origin: null,
metadata: {}
}
​Shipping zones determine the available shipping method(s) for a given shipping address. The match is evaluated against a set of regular expressions on the address (country, state, or zip code) of a customer. Now let’s create a new shipping zone to match Italy (IT), Spain (ES), Germany (DE), France (FR), and the United Kingdom (UK).
CLI command
Response
The following command creates a new shipping zone to match Italy (IT), Spain (ES), Germany (DE), France (FR), and the United Kingdom (UK):
cl resources:create shipping_zones -a \
name="European Countries" \
country_code_regex="IT|ES|DE|FR|UK"
On successful run, the newly created shipping zone object information is prompted:
{
id: 'kKwxmtNVYv',
type: 'shipping_zones',
name: 'European Countries',
country_code_regex: 'IT|ES|DE|FR|UK',
not_country_code_regex: null,
state_code_regex: null,
not_state_code_regex: null,
zip_code_regex: null,
not_zip_code_regex: null,
created_at: '2022-03-17T14:41:39.794Z',
updated_at: '2022-03-17T14:41:39.794Z',
reference: null,
reference_origin: null,
metadata: {}
}
​Shipping methods are used to provide customers with delivery options. Each shipping method can have a price and can be free if the order total is over a certain amount or based on some specific promotion rules. When you create a new shipping method you need to specify its cost (amount) and the currency code. If you associate the shipping method with a market, the currency will be inherited from the market's price list. You need also to associate it with a shipping zone and a shipping category. We will use the previously created ones.
CLI command
Response
The following command creates a new shipping method and associates it with a market, a shipping zone, and a shipping category.
cl resources:create shipping_methods -r \
market="BjydJhAPko" \
shipping_zone="kKwxmtNVYv" \
shipping_category="MWjgYFbYVK" -a \
name="Express Delivery" \
price_amount_cents="960" \
free_over_amount_cents="8900"
On successful run, the newly created shipping method object information is prompted. You can see that the currency code (EUR) has been inherited by the market's price list:
{
id: 'bVlBrFyGKO',
type: 'shipping_methods',
name: 'Express Delivery',
currency_code: 'EUR',
disabled_at: null,
price_amount_cents: 960,
price_amount_float: 9.6,
formatted_price_amount: '€9,60',
free_over_amount_cents: 8900,
free_over_amount_float: 89,
formatted_free_over_amount: '€89,00',
price_amount_for_shipment_cents: 960,
price_amount_for_shipment_float: 9.6,
formatted_price_amount_for_shipment: '€9,60',
created_at: '2022-03-17T14:44:22.650Z',
updated_at: '2022-03-17T14:44:22.650Z',
reference: null,
reference_origin: null,
metadata: {},
market: {
id: 'BjydJhAPko',
type: 'markets',
number: 9656,
name: 'Europe',
facebook_pixel_id: null,
checkout_url: null,
external_prices_url: null,
private: false,
created_at: '2022-03-17T14:39:47.525Z',
updated_at: '2022-03-17T14:39:47.525Z',
reference: null,
reference_origin: null,
metadata: {}
},
shipping_zone: {
id: 'kKwxmtNVYv',
type: 'shipping_zones',
name: 'European Countries',
country_code_regex: 'IT|ES|DE|FR|UK',
not_country_code_regex: null,
state_code_regex: null,
not_state_code_regex: null,
zip_code_regex: null,
not_zip_code_regex: null,
created_at: '2022-03-17T14:41:39.794Z',
updated_at: '2022-03-17T14:41:39.794Z',
reference: null,
reference_origin: null,
metadata: {}
},
shipping_category: {
id: 'MWjgYFbYVK',
type: 'shipping_categories',
name: 'Demo Shipping Category',
created_at: '2022-03-17T14:41:06.380Z',
updated_at: '2022-03-17T14:41:06.380Z',
reference: null,
reference_origin: null,
metadata: {}
}
}
​Payment gateways allow users to process payments through Commerce Layer's API. By default, we currently support Adyen, Braintree, Checkout.com, Klarna, PayPal, and Stripe. Manual gateways are also available (useful to process payments through wire transfer, cash, and other kinds of manual payment options). On top of that, external gateways let you integrate any payment service that is not available out-of-the-box (even your custom one). You can check the API references of each of them to understand the attributes/relationships required for their creation. For the purpose of this guide, we will create a manual gateway
CLI command
Response
The following command creates a new manual payment gateway:
cl resources:create manual_gateways -a name="Manual Gateway"
On successful run, the newly created manual payment gateway object information is prompted:
{
id: 'ExJwlspqmv',
type: 'manual_gateways',
name: 'Manual Gateway',
created_at: '2022-03-17T14:45:27.063Z',
updated_at: '2022-03-17T14:45:27.063Z',
reference: null,
reference_origin: null,
metadata: {},
require_capture: null
}
You can use the command
cl resources:list payment_gateways
to list all the payment gateway(s) created or cl resources:list <gateway_type>_gateways
to list only the specified ’s payment gateways created.​Payment methods represent the type of payment sources (e.g. credit card, PayPal, or Apple Pay) offered in a market. They can have a price and must be present before placing an order. By default, we currently support the following payment source types: Adyen payment, Braintree payment, Checkout.com payment, credit card, PayPal payment, Stripe payment, external payment, or wire transfer — based on the payment gateway to be associated with. The manual payment gateway only accepts the wire transfer payment source type and that's the one we will use to create the payment method, associated with the previously created payment gateway.
CLI command
Response
The following command creates a new payment method and associates it with a manual payment gateway and a wire transfer payment source:
cl resources:create payment_methods -r \
market="BjydJhAPko" \
payment_gateway="ExJwlspqmv" -a \
payment_source_type="WireTransfer"
On successful run, the newly created payment method object information is prompted:
{
id: 'lMAeGsQQWM',
type: 'payment_methods',
payment_source_type: 'wire_transfers',
name: 'Wire Transfer',
currency_code: 'EUR',
moto: false,
disabled_at: null,
price_amount_cents: 0,
price_amount_float: 0,
formatted_price_amount: '€0,00',
created_at: '2022-03-17T14:50:17.021Z',
updated_at: '2022-03-17T14:50:17.021Z',
reference: null,
reference_origin: null,
metadata: {},
market: {
id: 'BjydJhAPko',
type: 'markets',
number: 9656,
name: 'Europe',
facebook_pixel_id: null,
checkout_url: null,
external_prices_url: null,
private: false,
created_at: '2022-03-17T14:39:47.525Z',
updated_at: '2022-03-17T14:39:47.525Z',
reference: null,
reference_origin: null,
metadata: {}
},
payment_gateway: {
id: 'ExJwlspqmv',
type: 'payment_gateways',
name: 'Manual Gateway',
created_at: '2022-03-17T14:45:27.063Z',
updated_at: '2022-03-17T14:45:27.063Z',
reference: null,
reference_origin: null,
metadata: {}
}
}
​SKUs describe specific product variations that are being sold. To create an SKU you need to associate it with a shipping category that determines the available shipping options for that SKU. We will use the previously created one. You can add any additional optional attribute that fits your needs.
CLI command
Response
The following command created a new SKU and associates it with a shipping category:
cl resources:create skus -r \
shipping_category="MWjgYFbYVK" -a \
code="SKUCODE0001XLXX" \
name="Grey Aeron Ergonomic Office Chair" \
description="Aeron office chair is a revolutionized office seating with its defining design qualities and its patented PostureFit SL back support..." \
image_url="https://images.hermanmiller.group/m/7b7b8463a1433d26/W-REK_18179_20160811174200565.png" \
reference="SKUCODE0001" \
do_not_ship="false" \
do_not_track="false" \
weight="500" \
unit_of_weight="gr"
On successful run, the newly created SKU object information is prompted:
{
id: 'BorzSOKrYq',
type: 'skus',
code: 'SKUCODE0001XLXX',
name: 'Grey Aeron Ergonomic Office Chair',
description: 'Aeron office chair is a revolutionized office seating with its defining design qualities and its patented PostureFit SL back support...',
image_url: 'https://images.hermanmiller.group/m/7b7b8463a1433d26/W-REK_18179_20160811174200565.png',
pieces_per_pack: null,
weight: 500,
unit_of_weight: 'gr',
hs_tariff_number: null,
do_not_ship: false,
do_not_track: false,
created_at: '2022-03-17T14:54:33.123Z',
updated_at: '2022-03-17T14:54:33.123Z',
reference: 'SKUCODE0001',
reference_origin: null,
metadata: {},
shipping_category: {
id: 'MWjgYFbYVK',
type: 'shipping_categories',
name: 'Demo Shipping Category',
created_at: '2022-03-17T14:41:06.380Z',
updated_at: '2022-03-17T14:41:06.380Z',
reference: null,
reference_origin: null,
metadata: {}
}
}
A stock item keeps the available inventory of an SKU in a given stock location. When you create a stock item, you must specify its quantity, and the associated SKU must be available in one of the market's stock locations.
CLI command
Response
The following command creates a new stock item for a given SKU and associates it with a stock location:
cl resources:create stock_items -a \
sku_code="SKUCODE0001XLXX" \
quantity="100" -r \
stock_location="okdYzuXRDM"
On successful run, the newly created stock item object information is prompted:
{
id: 'YqAwfbkwlk',
type: 'stock_items',
sku_code: 'SKUCODE0001XLXX',
quantity: 100,
created_at: '2022-03-17T14:56:11.749Z',
updated_at: '2022-03-17T14:56:11.749Z',
reference: null,
reference_origin: null,
metadata: {},
stock_location: {
id: 'okdYzuXRDM',
type: 'stock_locations',
number: 8207,
name: 'Europe Warehouse',