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.

Manual seeding reference guide

Create an organization

These are the steps you need to follow to create an organization on Commerce Layer:

  1. Create a free developer account here. If you already have an account, please skip to step 3.

  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 select New organization from the dropdown to create a new one for your business. Then, on the following page, enter a name and select the region where your data will be stored, as seen in the screenshots below.

Once the organization is created, the chosen data storage location cannot be changed anymore. 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 support@commercelayer.io specifying the list of the organization slug you want to be deleted.

Create integration API credentials

Follow these steps to create new integration API credentials (client ID, client secret, and base endpoint) from the Dashboard with an Admin role. Remember to save them as we'll use them later to interact with the CLI.

Install the Commerce Layer 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.

Log in using the API credentials

Log in via the CLI using the previously created integration API credentials like so:

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 from https://sample-shop.commercelayer.io).

  • The -i flag allows you to pass in a client ID as a parameter.

  • <clientId> represents your client ID (you can find it on the API credentials details page on the dashboard).

  • The -s flag allows you to pass in a client secret as a parameter.

  • <clientSecret> represents your client secret (you can find it on the API credentials 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 different API credentials).

Install the resources plugin

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.

Configure your organization

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:

  • A description of the resource with a link to the related object details in the API reference.

  • 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).

Markets

Address

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.

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="sample-shop@example.com"

Merchant

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.

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"

Stock location

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.

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"

Inventory model

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.

The following command creates a new inventory model:

cl resources:create inventory_models -a name="EUR Inventory"

Inventory stock location

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.

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"

Price list

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).

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"

Market

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.

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"

Shipping

Shipping category

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.

The following command creates a new shipping category:

cl resources:create shipping_categories -a name="Demo Shipping Category"

Shipping zone

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).

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"

Shipping method

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.

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"

Payments

Payment gateway

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

The following command creates a new manual payment gateway:

cl resources:create manual_gateways -a name="Manual Gateway"

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 method

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.

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"

Products

SKUs

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.

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"

Stock items

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.

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"

Prices

Prices are the defined cost price of an SKU associated with a currency and price list. When a customer purchases an SKU, it gets the price associated with the order's price list for that market. When you create a price, you must specify the amount and the compare-at amount. The currency is defined by the associated price list.

The following command creates a price for a given SKU and associates it with a price list:

cl resources:create prices -a \
  sku_code="SKUCODE0001LXXX" \
  amount_cents="4990" \
  compare_at_amount_cents="4500" -r \
  sku="BorzSOKrYq" \
  price_list="dlwQyCXnqB"

Import additional resources

Commerce Layer lets you import multiple resources (e.g. orders, coupons, SKUs, prices, stock items, customers, and more) in batches directly with our imports API. All you have to do is create a new import resource, specify the resource type you want to import, and populate the inputs attribute with a JSON list of items. Each element of the inputs array contains the resource attributes and relationships. You can learn more about importing resources in our documentation.

Importing resources

To do that using the CLI, first you need to install the imports plugin:

cl plugins:install imports

Then create a JSON file named skus.json with an array containing the list of additional SKUs you want to import:

[
  {
    "code": "BEACHBAGFFFFFF000000XXXX",
    "name": "White Beach Bag with Black Logo",
    "description": "Meet your companion for a sunny summer day — our beach bag! It's large, comfy, and you can match it with our towel to create the perfect beach combo.",
    "image_url": "https://data.commercelayer.app/seed/images/skus/BEACHBAGFFFFFF000000XXXX_FLAT.png",
    "reference": "BEACHBAGFFFFFF000000",
    "shipping_category_id": "MWjgYFbYVK"
  },
  {
    "code": "BEANIEXX000000FFFFFFXXXX",
    "name": "Black Beanie with White Logo",
    "description": "Soft double-layered customizable beanie. 95% polyester, 5% spandex. Regular fit. Accurately printed, cut, and hand-sewn.",
    "image_url": "https://data.commercelayer.app/seed/images/skus/BEANIEXX000000FFFFFFXXXX_FLAT.png",
    "reference": "BEANIEXX000000FFFFFF",
    "shipping_category_id": "MWjgYFbYVK"
  }
]

Also, create a JSON file named stock_items.json with an array containing the list of the related stock items:

[
  {
    "sku_code": "BEACHBAGFFFFFF000000XXXX",
    "quantity": 200
  },
  {
    "sku_code": "BEANIEXX000000FFFFFFXXXX",
    "quantity": 95
  }
]

Lastly, create a JSON file named prices.json with an array containing the list of the related prices:

[
  {
    "sku_code": "BEACHBAGFFFFFF000000XXXX",
    "amount_cents": 3990,
    "compare_at_amount_cents": 5000
  },
  {
    "sku_code": "BEANIEXX000000FFFFFFXXXX",
    "amount_cents": 3490,
    "compare_at_amount_cents": 4700
  }
]

Now you can import the two SKUs with their prices and stock items as seen in the snippets below:

The following command imports the SKUs specified in a file:

cl imports:create -t skus -i <input-file-path>

The following command imports the stock items specified in a file and associates them with a stock location:

cl imports:create -t stock_items -p <stock_location-id> -i <input-file-path>

The following command imports the prices specified in a file and associates them with a price list:

cl imports:create -t prices -p <price-list-id> -i <input-file-path>

If you run into any error, you can run cl imports:details <ID> -l to view the error log for that import process using the process ID.

Create an order

An order consists of a customer, some line items (SKUs, shipping method, payment method, taxes, etc.), a billing address, a shipping address, discount(s) calculated from active promotions, redeemed gift card(s), a payment method, and a payment source type. The sections below will walk you through the process of creating an order by associating it with the required resources, step by step.

Remember that to place and checkout an order you can also leverage our hosted checkout application (automatically enabled for every Commerce Layer account) — if you want to learn more about how to generate a checkout URL using our CLI, feel free to skip the manual steps below and jump directly here.

Search for the ID of the SKU you intend to purchase

You can find the ID of the SKU you want to purchase in the dashboard. Alternatively, you can use the CLI:

The following command will search for all SKUs and filter out the results:

cl resources:get skus -w name_i_cont_all=t-shirt,black -w name_not_i_cont_all=women,white

Search for the ID of the market you intend to purchase from

You can find the ID of the market you want to purchase from in the dashboard. Alternatively, you can use the CLI (feel free to filter out the results as shown in the previous section if the list of your markets is too long):

The following command will search for all existing markets:

cl resources:get markets

Create a new order

Now you can create a new order for the market you selected:

The following command creates a new order and associates it with a market:

cl resources:create orders -r market=markets/QlNQVhWxbg