Manual configuration
A step-by-step guide on how to set up an organization from scratch, using our CLI
Last updated
A step-by-step guide on how to set up an organization from scratch, using our CLI
Last updated
If you want to get deeper and understand the Commerce Layer data model in detail, you may want to try to configure your organization manually, directly interacting with our APIs by leveraging the . 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. 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.
As an alternative, if you want to go straight to the chase, you can available on the Dashboard UI when you create a new organization.
Run the command below on your terminal to install the CLI using your favorite package manager:
Installing the CLI provides access to the commercelayer
command, which can also be accessed with the aliases clayer
and cl
.
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).
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.
The following command fetches a collection of SKUs using the CLI, prompting you the options to select a format to show the command live documentation:
The command for creating the resource.
The output response of the successfully run command.
The following command creates a new address:
The following command creates a new merchant and associates it with a billing address:
The following command creates a new stock location and associates it with an address:
The following command creates a new inventory model:
The following command creates a new inventory stock location and associates it with a stock location and an inventory model:
The following command creates a new price list associated with the European currency, with tax included (default):
The following command creates a new market and associate it list associates it with a merchant, an inventory model, and a price list:
The following command creates a new shipping category:
The following command creates 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 method and associates it with a market, a shipping zone, and a shipping category.
The following command creates a new manual payment gateway:
The following command creates a new payment method and associates it with a manual payment gateway and a wire transfer payment source:
The following command created a new SKU and associates it with a shipping category:
The following command creates a new stock item for a given SKU and associates it with a stock location:
The following command creates a price for a given SKU and associates it with a price list:
Then create a JSON file named skus.json
with an array containing the list of additional SKUs you want to import:
Also, create a JSON file named stock_items.json
with an array containing the list of the related stock items:
Lastly, create a JSON file named prices.json
with an array containing the list of the related prices:
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:
The following command imports the stock items specified in a file and associates them with a stock location:
The following command imports the prices specified in a file and associates them with a price list:
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:
The following command will search for all existing markets:
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:
Now you can add the SKU to the newly created order by associating the related line item. Use the quantity
attribute to add multiple units of the same product:
The following command creates a line item and associates it with an order and an SKU:
The order must now be updated to be associated with a customer using the customer's email:
The following command associates a customer email with an order:
Now you need to create an address that will be use used to checkout the order:
The following command creates a new address:
The previously created address will be used both as the billing and the shipping address of the order:
The following command associates a shipping and billing address with an order:
To choose a shipping method for the shipment(s) associated with your order, you need first to check what are the available ones:
The following command fetches the shipments associated with an order and all the available shipping methods:
Now you can associate the desired shipping method with the shipment:
The following command associates a selected shipping method with a shipment:
To choose a payment method for your order, you need first to check what are the available ones:
The following command fetches the payment methods associated with an order:
Now you can associate the desired payment method with the order:
The following command associates a selected payment method with an order:
The following command creates a wire transfer payment source type and associates it with an order:
Finally, you can place the order by triggering the _place
method:
The following command places the order:
Where:
If you have already logged in, you can just switch to the sales channel API credentials using the command below:
If you have the ID of an order ready to be placed, you can generate a valid checkout URL like so:
The following command creates a checkout URL associated with an order:
Alternatively, you can add new items to an order or directly create a new one and then place it, like so:
The following command creates an order and the related line items, associated with one or more SKUs. It also creates a checkout URL associated with the order:
Here’s a breakdown of each of the command options:
The checkout
command uses the installed checkout plugin.
The -O
flag allows you to pass in an order ID.
The -S
flag allows you to pass in an SKU code.
The -m
flag allows you to pass in a market ID.
The -e
flag allows you to pass in a customer email.
The -c
flag allows you to pass in a coupon code.
The -B
flag allows you to pass in a bundle code.
As soon as you and your account is successfully confirmed, you will be prompted to create your first organization. Otherwise, if you already have an account, click on your current organization name in the left upper corner of your dashboard homepage to access your list of 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 specifying the list of the organization slug you want to be deleted.
Follow 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 .
Log in via the CLI using the integration API credentials like so:
To get started, you need to install the so that you can execute CRUD operations on the API resources. To do that, use the command below:
You can run the command cl resources
to list all the available Commerce Layer API and a link to the documentation of each one. Use commercelayer resources --help
to see the available commands and what they do.
To get your organization ready to receive orders, you need to create some resources. These resources are grouped into , , , and . The sections below describe each of these resources in sequential order, and how to create them using the 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 .
A link to the related where you can check the flowchart that illustrates how the specific resource relates to other API entities.
The 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.
A 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 address resource.
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 and use the new address ID here. To keep it simple, we’ll use the merchant’s address.
An 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 .
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.
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).
A 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.
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.
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).
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.
allow users to process payments through Commerce Layer's API. By default, we currently support , , , , , and . are also available (useful to process payments through wire transfer, cash, and other kinds of manual payment options). On top of that, 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
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: , , , credit card, , , , or — 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.
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 one. You can add any additional optional attribute that fits your needs.
A 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.
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.
Commerce Layer lets you import multiple resources (e.g. orders, coupons, SKUs, prices, stock items, customers, and more) in batches directly with our . 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.
To do that using the CLI, first you need to install the :
An 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 .
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 if the list of your markets is too long):
You can associate different addresses for shipping and billing. All you need to do is create another address as described in the and associate the ID here.
To place the order you need now to create a related to the selected payment method:
Follow to create new sales channel API credentials (client ID and base endpoint) from the dashboard. Remember to save them as we'll use them to later.
You can create a checkout link using our application. With this, you can checkout an order in a web browser. To get started, you need to install the using the command below:
Only a access token can be used to generate a checkout URL. So, use the command below to log with your sales channel API credentilas (similar to what you did ):
The -S
flag is required for sales channels and allows you to pass in your as a parameter.
Now that your first organization is properly configured and you managed to place your first order, you can take the time to explore the rest of this getting started section, check the , have a look at our recipe-like , and become a pro!
Do you need to extract some kind of data information from your Commerce Layer's organization? We've got you covered. Check our and see how it can enable you to gather and aggregate useful data that you can leverage to measure the health and performance of your ecommerce business.
If you want to exercise greater control over your organizational structure and user roles and be able to manage provisioning tasks programmatically instead of manually, leverage our .
Would you like to benefit from a DSL that enables you to define promotional rules? If you're an enterprise customer, you can ask to test our and start setting up almost any kind of promotions to boost your sales, from the simplest to the most complex.
For everything else, and feel free to ask any questions to the team or get involved in the conversation with the rest of our developers' community.