Setting Up commercetools Project and API
The first step before any development is correct Project setup: regions, currencies, languages, channels, stores, and API clients. Mistakes at this stage are expensive to fix: moving a Project between regions is not supported, and incorrect channel structure breaks pricing.
Choosing a Region
commercetools operates on GCP and AWS in multiple regions:
| Region | API Host | Auth Host |
|---|---|---|
| Europe (GCP) | api.europe-west1.gcp.commercetools.com |
auth.europe-west1.gcp.commercetools.com |
| US East (GCP) | api.us-central1.gcp.commercetools.com |
auth.us-central1.gcp.commercetools.com |
| Australia | api.australia-southeast1.gcp.commercetools.com |
auth.australia-southeast1.gcp.commercetools.com |
| Europe (AWS) | api.eu-west-1.aws.commercetools.com |
auth.eu-west-1.aws.commercetools.com |
For CIS markets — europe-west1.gcp. Region is fixed when creating a Project and does not change.
Initial Configuration via Merchant Center
After creating a Project in mc.commercetools.com, configure basic settings:
Settings → International:
- Languages:
ru,en(first is default) - Currencies:
RUB,USD,EUR - Countries:
RU,BY,KZ
These settings determine allowed values for prices, translations, and shipping throughout the Project.
Channels and Stores
Channel — abstraction for pricing and inventory. Store — point of sale with catalog filtering.
// Create Channel
const channel = await apiRoot.channels().post({
body: {
key: "storefront-ru",
roles: ["ProductDistribution", "InventorySupply"],
name: { ru: "Сайт Россия", en: "Website Russia" },
defaultLocale: "ru",
defaultCurrency: "RUB",
address: { country: "RU" },
},
}).execute();
// Create Store with Channel binding
const store = await apiRoot.stores().post({
body: {
key: "web-ru",
name: { ru: "Веб-магазин Россия" },
countries: [{ code: "RU" }],
languages: ["ru"],
distributionChannels: [{ typeId: "channel", id: channel.body.id }],
supplyChannels: [{ typeId: "channel", id: channel.body.id }],
},
}).execute();
If multiple websites are needed (RU/BY/KZ), create a separate Channel and Store for each.
Setting Up API Clients
Each service gets a separate API Client with minimal required permissions:
// Via Merchant Center: Settings → Developer settings → Create client
// Recommended clients:
// 1. storefront-anonymous — view_products, view_categories, manage_my_carts, manage_my_orders
// 2. storefront-customer — + manage_my_profile, manage_my_payments
// 3. backend-import — manage_products, manage_orders, manage_customers
// 4. extensions — manage_orders, view_payments
// 5. terraform — manage_project (infrastructure tasks only, not in code)
Client for storefront (anonymous):
const anonymousAuthMiddleware = createAuthMiddlewareForAnonymousSessionFlow({
host: "https://auth.europe-west1.gcp.commercetools.com",
projectKey: process.env.CTP_PROJECT_KEY!,
credentials: {
clientId: process.env.CTP_STOREFRONT_CLIENT_ID!,
clientSecret: process.env.CTP_STOREFRONT_CLIENT_SECRET!,
},
scopes: [
`view_products:${process.env.CTP_PROJECT_KEY}`,
`manage_my_carts:${process.env.CTP_PROJECT_KEY}`,
`manage_my_orders:${process.env.CTP_PROJECT_KEY}`,
],
});
Client for logged-in user:
const customerAuthMiddleware = createAuthMiddlewareForPasswordFlow({
host: "https://auth.europe-west1.gcp.commercetools.com",
projectKey: process.env.CTP_PROJECT_KEY!,
credentials: {
clientId: process.env.CTP_STOREFRONT_CLIENT_ID!,
clientSecret: process.env.CTP_STOREFRONT_CLIENT_SECRET!,
user: { username: email, password },
},
scopes: [
`manage_my_profile:${process.env.CTP_PROJECT_KEY}`,
`view_orders:${process.env.CTP_PROJECT_KEY}`,
],
});
Terraform for Version-Controlled Configuration
Project configuration in Git is a best practice for reproducible environments:
# main.tf
terraform {
required_providers {
commercetools = {
source = "labd/commercetools"
version = "~> 1.4"
}
}
}
provider "commercetools" {
client_id = var.ctp_client_id
client_secret = var.ctp_client_secret
project_key = var.ctp_project_key
token_url = "https://auth.europe-west1.gcp.commercetools.com"
api_url = "https://api.europe-west1.gcp.commercetools.com"
}
resource "commercetools_channel" "storefront_ru" {
key = "storefront-ru"
roles = ["ProductDistribution", "InventorySupply"]
name = {
ru = "Сайт Россия"
en = "Website Russia"
}
}
resource "commercetools_store" "web_ru" {
key = "web-ru"
name = { ru = "Веб-магазин Россия" }
languages = ["ru", "en"]
countries = ["RU"]
distribution_channels = [commercetools_channel.storefront_ru.key]
supply_channels = [commercetools_channel.storefront_ru.key]
}
terraform init
terraform plan
terraform apply
Attribute Types (Product Types)
Product Type — attribute schema for a product group. Attribute type cannot be changed after creation, only deleted and recreated.
await apiRoot.productTypes().post({
body: {
key: "apparel",
name: "Одежда",
description: "Атрибуты для одежды",
attributes: [
{
name: "brand",
label: { ru: "Бренд", en: "Brand" },
type: { name: "text" },
isRequired: false,
isSearchable: true,
},
{
name: "size",
label: { ru: "Размер", en: "Size" },
type: {
name: "enum",
values: [
{ key: "XS", label: "XS" },
{ key: "S", label: "S" },
{ key: "M", label: "M" },
{ key: "L", label: "L" },
{ key: "XL", label: "XL" },
],
},
isRequired: true,
isSearchable: true,
},
],
},
}).execute();
Checklist Before Development
- Region chosen, Project created
- Languages and Currencies configured in Settings
- Channels created (minimum 1 per storefront)
- Stores bound to Channel
- API Clients created with minimal scopes
- Product Types defined (agree schema with content team)
- Shipping zones added
- Tax categories created
- Configuration uploaded to Terraform (optional, but recommended)
Time for initial Project setup — 1–2 business days with clear catalog structure requirements.







