Commerce Integration Layer

Ask about this Page
Copy for AI
View as Markdown

Author, run, validate, publish, and inspect Commerce Integration Layer extensions from the terminal.

The integration-layer topic is the tooling for the Commerce Integration Layer. Use it to scaffold an extensions project, run it locally, validate it, publish it, and manage the configuration of your Project.
The topic is not bundled with the CLI. You install it on demand as a plugin from the public npm registry. This page is the full reference: every command, every flag, how the commands authenticate, and which host each one talks to. For writing extensions, see Get started and Write Schema Extensions.

Install

Install the CLI and the pluginbash
npm install -g @commercetools/cli
commercetools plugins install @commercetools/cli-topic-integration-layer
Then log in with an API Client that has the manage_project scope, as described in Authentication.

To check the installed version of the plugin:

Check the plugin versionbash
commercetools integration-layer --version

Commands that need a login

The topic has no credential file of its own. It reuses the session from commercetools auth login, including your Project key and Region. For how to log in, see Authentication.
A command that needs a login fails immediately with not logged in — run 'commercetools auth login' first and does not attempt the call.
Needs a loginRuns offline
explore, schema fetch, extension push, extension pull, extension status, extension serve-api-extension, config, allowlist, project-settings, idp-login, checkout-rules, field-visibilityinit, extension build, extension invoke-api-extension (local), extension create-api-extension-input, extension serve (standalone)

Two commands are conditional:

  • extension validate needs a login only for its remote checks. Pass --skip remote to run it fully offline.
  • extension serve needs a login only with --compose, --gateway, or --all, which reach the Commerce Integration Layer.

Hosts

The Commerce Integration Layer has three public hosts per Region. The plugin derives all of them from the Region of your login, so you do not need to set anything.

EdgeDerived hostServes
Extensionshttps://extensions.integration-layer.{region}.commercetools.comThe routes that need manage_project: the subgraph, extensions, and configuration
Experience APIhttps://graphql.integration-layer.{region}.commercetools.comThe shopper GraphQL API, where operations run
Shopper Identity APIhttps://auth.integration-layer.{region}.commercetools.comSession minting and the core subgraph that the local gateway routes to
Only the Extensions edge can be overridden, with --integration-layer-url or INTEGRATION_LAYER_URL, for example to point at a local edge. If your login has no Region, the command fails and prints the expected URL shape.

Global flags

These flags are available on every authenticated command.

FlagEnvironment variablePurpose
--integration-layer-urlINTEGRATION_LAYER_URLBase URL of the Extensions edge. Overrides the Region-derived host.
--project-keyAct on a different Project than the one you are logged in to
Every authenticated command, plus extension serve and extension invoke-api-extension, also accepts --env-file <path>. The dotenv file is loaded before the command runs. By default, .env in the current directory is loaded if it exists. A variable that is already set in your shell always wins over the file.

One bundle per Project

A Project deploys exactly one bundle: one federation subgraph that the router composes with the core subgraph. A push replaces the previous bundle entirely.

That does not mean one file. The build, validate, push, and serve commands accept --all. It finds every package under ./extensions/* that has a src/extension.ts, sorts them by name, and merges their typeDefs, resolvers, and apiExtensions into a single subgraph and artifact.
Scaffold and push an extensions projectbash
commercetools integration-layer init my-extensions
cd my-extensions
pnpm push
Use --extensions-dir <dir> (default extensions) to discover packages elsewhere. Two extensions can each add fields to Query. They only clash if they declare the same field.
Without --all, every command works on one extension: it reads src/extension.ts and writes dist/extension.js relative to the directory you run it in.

Command reference

init

Scaffold an extensions projectbash
commercetools integration-layer init [DIRECTORY] [--template basic] [--force]

Scaffolds an extensions monorepo with:

  • A pnpm workspace with the root scripts wired to the --all flow
  • Shared TypeScript and ESLint configuration
  • One buildable hello-world extension under extensions/, with a Vitest test
Run the tests with pnpm test. Everything is bundled with the plugin, so no network access is needed. The command refuses to scaffold into a non-empty directory unless you pass --force.
Argument or flagDefaultDescription
DIRECTORY.The directory to scaffold into
--templatebasicThe template. Only basic is available.
-f, --forcefalseScaffold into a non-empty directory

extension build

Build the extensionbash
commercetools integration-layer extension build [--entry <file>] [--out <file>] [--all] [--extensions-dir <dir>]
Bundles the extension into one self-contained CommonJS artifact with esbuild. graphql stays external. The command runs offline.
FlagDefaultDescription
--entrysrc/extension.tsThe extension source file
--outdist/extension.jsThe output artifact
--all, --extensions-dirSee One bundle per Project

extension serve

Serve the extension locallybash
commercetools integration-layer extension serve [--port 4000] [--entry <file>] [--compose] [--gateway] [--all] [--env-file <path>]
Starts a local GraphQL server with GraphiQL and a file watcher. It calls your resolvers with the same ctx they get in production: ctx.now(), and ctx.config from EXTENSION_CONFIG_* variables in the environment, a .env file, or --env-file. Saving the extension source reloads the schema, and saving the .env file reloads ctx.config, both without a restart.
If you are logged in, the same HTTP allowlist as in production limits the fetch calls of your resolvers. This requires the Commerce Integration Layer to be reachable. Without a login, or when offline, fetch is unrestricted locally and a warning is printed.
Mode/graphql isReaches the Commerce Integration LayerExtra routes
DefaultYour extension subgraphNo, fully offlineNone
--composeYour extension subgraphYes, to fetch the schema/composed, /schema.graphql, /supergraph.graphql
--gatewayA federated gateway over your extension and the deployed Commerce Integration LayerYes/_extension
--allA gateway over the merged extensions/* subgraph and the Commerce Integration LayerYes/_extension, /composed
In the default mode, test entity fields such as Product.loyaltyPoints through the _entities query. With --gateway, one query such as { product(id: …) { name loyaltyPoints(price: …) } } resolves name upstream and loyaltyPoints locally. The gateway mints an anonymous session for its upstream calls.
Pass flags from inside the extension directory, for example pnpm dev --gateway. The root pnpm dev:<example> shortcut only covers the default mode.

extension validate

Validate the extensionbash
commercetools integration-layer extension validate [--skip local|remote] [--all] [--entry <file>] [--out <file>]

Runs the publish checks without uploading anything, in this order:

CheckWhereSkippable with --force on push
Static analysis. Rejects use of globals that the sandbox does not provide, such as process, node:*, and eval.LocalNo
Shape and coherence. Non-empty typeDefs, a resolvers object, a resolver for every field the schema declares, and well-formed apiExtensions. A bundle must contribute at least one of the two kinds.LocalNo
Composition against the live core subgraph of your ProjectRemoteYes
Breaking-change detection against your published schemaRemoteYes
--skip local and --skip remote run only the other half. A Project's first extension has no published schema to compare with, so the breaking-change check does not apply to it. A bundle with only API Extensions skips composition.

extension push

Push the extensionbash
commercetools integration-layer extension push [--force] [--all] [--source-revision <rev> | --no-source-revision] [--no-wait] [--wait-timeout 180]

Builds, validates, and uploads the bundle, replacing the one stored for the Project. A push is how a published extension changes. You cannot unpublish an extension. To remove it, remove the Commerce Integration Layer from the Project and set it up again.

FlagDefaultDescription
-f, --forcefalseUpload despite failing remote validation. The local checks always fail the command, because a bundle that cannot load is broken whatever you intended.
--source-revisionDetected from gitThe revision to record with the bundle. Environment variable: EXTENSION_SOURCE_REVISION.
--no-source-revisionfalsePush without recording a revision
--wait, --no-wait--waitWait for the extension runtime to load the pushed version and report back
--wait-timeout180Seconds to wait before giving up. The push still stands.
A push only stores the bundle, and the runtime loads it afterwards. Waiting is what catches a bundle that is stored cleanly but refuses to run. A failed result exits with a non-zero code. Not being able to find out the result never does.
When you run it through a package script, forward flags explicitly, for example pnpm push -- --force. A bare pnpm push --force can be swallowed by pnpm.

extension status

Show the stored bundlebash
commercetools integration-layer extension status

Shows the bundle stored for the Project:

  • Version and size in bytes
  • Upload time, filename, and who updated it
  • The revision it was built from, if the push recorded one

It reports the stored bundle, not whether the runtime loaded it.

extension pull

Download the stored bundlebash
commercetools integration-layer extension pull [--out <file>] [--force]
Downloads the bundle that is stored for the Project to a file. By default, it writes the file under ./dist with the stored filename.
FlagDescription
--outThe file to write the bundle to. The default is the stored filename under ./dist.
-f, --forceOverwrite the output file if it already exists

extension invoke-api-extension

Invoke API Extension handlersbash
commercetools integration-layer extension invoke-api-extension --input <file.json> [--key <key>]... [--all] [--config KEY=VALUE]... [--env-file <path>]
commercetools integration-layer extension invoke-api-extension --deployed --input <file.json> [--project-key <key>]
Sends a commercetools API Extension callback to your handlers and prints the decision: APPROVE, MODIFY with the update actions, or the blocking errors. It has two targets:
  • Local (default). Runs the handlers of the bundle in-process. It needs no deployment and no credentials, and runs offline. Each handler is reported separately, and --key narrows the run to named handlers. ctx.config comes from EXTENSION_CONFIG_* variables, a .env file, or --env-file, and a --config entry overrides the same key.
  • --deployed. Sends the callback to the deployed extension of your Project through the Commerce Integration Layer, so it exercises the live code. It needs a login. Nothing is persisted. It returns one merged result, without a per-handler breakdown.
--input is required for both targets. It is a JSON commercetools ExtensionInput with action and resource, including resource.typeId. A handler runs only when its resourceTypeId and actions match the payload. Locally, the others are reported as skipped. Use extension create-api-extension-input to create a realistic payload.
--deployed cannot be combined with the local-only flags --all, --extensions-dir, --entry, --out, --config, or --key.
FlagDescription
--inputRequired. Path to the JSON ExtensionInput.
--deployedSend the callback to the deployed extension of the Project. Needs a login.
--keyRepeatable. Only invoke the handlers with these keys. Local only.
--all, --extensions-dirInvoke the merged bundle. Local only.
--configRepeatable KEY=VALUE that becomes ctx.config. Local only.
--env-filePath to a dotenv file
--project-key, --integration-layer-urlOverride the project or edge of your login. --deployed only.
Invoke handlers with sample payloadsbash
commercetools integration-layer extension create-api-extension-input --resource-type cart --action Create --out ./payloads/cart-create.json
commercetools integration-layer extension invoke-api-extension --input ./payloads/cart-create.json
commercetools integration-layer extension invoke-api-extension --input ./payloads/cart-update.json --config MAX_LINE_QUANTITY=10
commercetools integration-layer extension invoke-api-extension --input ./payloads/order-create.json --key order-tagger
commercetools integration-layer extension invoke-api-extension --deployed --input ./payloads/cart-create.json
Locally, the command fails if the bundle declares no apiExtensions. With --deployed, it fails if the Project is not enrolled or has no deployed extension yet. For the concept, see Managed API Extensions.

extension serve-api-extension

Serve API Extension handlersbash
commercetools integration-layer extension serve-api-extension --public-url <url> [--port 4000] [--config KEY=VALUE]... [--all] [--extensions-dir <dir>] [--entry <file>] [--out <file>] [--cleanup] [--env-file <path>]
Debugs API Extensions end to end on your machine. It serves the apiExtensions handlers over HTTP. It also registers a commercetools API Extension that points at them. A real cart or order write in your Project then calls the code on your machine. The handlers run in plain Node, so you can attach a debugger and set breakpoints. Editing src/extension.ts reloads the handlers, and a changed trigger or condition registers again automatically.

commercetools must reach a public HTTPS URL, so run your own tunnel and pass its address:

Debug API Extensions through a tunnelbash
ngrok http 4000
commercetools integration-layer extension serve-api-extension --public-url https://abc123.ngrok.app
Do a matching cart write in the Project, then press Ctrl+C to deregister and exit. To remove leftovers after a crash, run --cleanup. Any tunnel works, for example cloudflared tunnel --url http://localhost:4000.
The command needs a manage_project login, because it calls the commercetools API directly. It is a separate command from serve on purpose: serve is a safe local server that never registers anything, while this command registers a callback in commercetools. Use a dedicated development or sandbox Project.

Safety behavior:

  • Before registering, it inspects the existing Extensions of the Project and refuses only if one already triggers on the same resource and action. Unrelated Extensions are left alone.
  • It owns everything it creates under the il-localdev- key prefix and deletes those when it exits.
FlagDefaultDescription
--public-urlRequired, unless you use --cleanup. The base URL of the tunnel. commercetools calls <public-url>/api-extensions.
-p, --port4000The local port to listen on
--configRepeatable KEY=VALUE that becomes ctx.config
--allfalseServe and register the combined bundle of every ./extensions/* package
--extensions-dirextensionsThe directory that holds the extension packages. Used with --all.
--cleanupfalseRemove leftover il-localdev-* Extensions and exit without serving
--env-filePath to a dotenv file

The command fails in these cases:

  • The bundle declares no apiExtensions.
  • An existing Extension collides with a resource and action that the command would register.
  • With --all, two packages declare the same API Extension key.

extension create-api-extension-input

Create a sample ExtensionInputbash
commercetools integration-layer extension create-api-extension-input --resource-type <type> [--action Create|Update] [--out <file.json>] [--id <id>]
Writes a realistic commercetools ExtensionInput JSON sample for testing handlers locally. The supported resource types come from the commercetools SDK, for example cart, order, and payment. The output is a { action, resource } object whose resource.obj carries the fields a handler typically reads.
FlagDefaultDescription
--resource-typeRequired. The resource type, for example cart.
--actionCreateCreate or Update. Update samples carry version: 2.
--outWrite to this file. Without it, the JSON is printed.
--idsample-{resource-type}-idThe resource ID in the sample

explore

Open the explorerbash
commercetools integration-layer explore [--port 4000] [--deployed] [--as <email>] [--locale <l>] [--currency <c>] [--country <co>]
Opens a local GraphQL explorer for the deployed edge of your Project. It resolves the schema, mints a session from your login, serves GraphiQL on http://localhost:4000, and proxies every operation to the real endpoint. You paste no tokens and edit no headers.
FlagDescription
--deployedShow the deployed composed schema of the Project, read from the registry, instead of composing it locally
--as <email>Run operations as that customer, with an ordinary email and password login. The command prompts for the password, or reads IL_CUSTOMER_PASSWORD. Without it, operations run anonymously.
--locale, --currency, --countryPresentment values, applied when the session is created. They default to the ones of the Project.
-p, --portThe local port. Default 4000.
Two schema sources are available. By default, the explorer composes the schema locally. It uses the core subgraph of your Project plus, when you run it from an extension directory, that extension built from your working tree. Your fields show up before you push. With --deployed, it shows what the router actually serves.

Things to know:

  • Authentication. Operations run as an anonymous shopper or as a customer who logs in with their own credentials. The command has no impersonation flag.
  • Attribution. The proxy sets graphql-client-name and graphql-client-version on every operation, so usage reports show the explorer traffic as coming from the CLI.
  • Network access. The explorer page loads GraphiQL and React from esm.sh in your browser, so it does not render on a fully offline machine. Nothing about your Project is sent to that host. All GraphQL operations go to your own edge through the local proxy.
  • Introspection. The deployed edge has introspection turned off, so the explorer reads the schema over an authenticated API and answers introspection itself. The session token is attached by the CLI and is never exposed to the browser page.

project-settings

Get and set Project settingsbash
commercetools integration-layer project-settings get [--json]
commercetools integration-layer project-settings set [--label <text>] [--language <code>] [--currency <code>] [--country <code>]
The settings that you can edit on the Project Settings tab in the Merchant Center. These are the display label and the default language, currency, and presentment country. The Region and the public endpoints are owned by the Commerce Integration Layer and cannot be set.
set changes only the fields that you pass and keeps the others. It checks --language, --currency, and --country against the values that the Project presents. The Project's own spelling is stored, so --country de saves DE. A value that the Project does not present is refused, and the command prints the list that it does present.
Set the currency and countrybash
commercetools integration-layer project-settings set --currency EUR --country DE

idp-login

Manage IdP loginbash
commercetools integration-layer idp-login get [--json]
commercetools integration-layer idp-login set [--issuer <url>] [--token-endpoint <url>] [--revocation-endpoint <url>] [--jwks-uri <url>] [--authorization-endpoint <url>] [--client-id <id>] [--client-secret <secret>] [--redirect-uri <url>] [--claim-external-id <claim>] [--claim-email <claim>] [--claim-first-name <claim>] [--claim-last-name <claim>] [--claim-phone <claim>] [--match-strategy externalId|email]
commercetools integration-layer idp-login delete [--force]
The external OpenID Connect identity provider that shoppers can sign in with. It matches the IdP Login tab in the Merchant Center. The client secret is write-only: get only reports whether one is set.
The first set needs the issuer, the token, revocation, and JSON Web Key Set (JWKS) endpoints, the client ID, the redirect URI, and the client secret. The claim mapping defaults to sub, email, given_name, family_name, and phone_number, and users are matched by external ID. After that, set changes only the flags that you pass, and leaving out the secret keeps the stored one. --authorization-endpoint '' clears the optional authorization endpoint.
Pass the secret in the IDP_CLIENT_SECRET environment variable instead of the flag, so it stays out of the process list and your shell history. The token, revocation, and JWKS endpoints must be absolute http or https URLs without embedded credentials.
delete disables IdP login for the Project, so it asks for confirmation. --force skips the prompt. Without a terminal, the command refuses unless you pass --force.

checkout-rules

Manage checkout rulesbash
commercetools integration-layer checkout-rules get [--json]
commercetools integration-layer checkout-rules add --application-key <key> [--mode PAYMENT_ONLY|COMPLETE] [--country <CC,...>] [--store <key,...>] [--position <n>]
commercetools integration-layer checkout-rules remove <position> [--force]
commercetools integration-layer checkout-rules set --file <path|-> [--force]
Decides which commercetools Checkout Application the Commerce Integration Layer names when it creates a Checkout Session. It matches the Checkout tab in the Merchant Center. The rules are an ordered list, and the first rule that matches the country and the store of the shopper wins. A rule lists countries (ISO 3166-1 alpha-2 codes) and store keys, each matched with OR. Leave one out to match any. A rule with neither matches every shopper, so put it last.
CommandEffect
getPrints the rules in match order. remove takes these positions.
addInserts one rule. It appends by default, before an existing catch-all rule. --position places it elsewhere, but never after a catch-all.
removeDrops the rule at a position. Asks for confirmation unless you pass --force.
setReplaces the whole list from a JSON file, or from standard input with -. Asks for confirmation unless you pass --force.
set suits pipelines, where you keep the rules in version control:
checkout-rules.jsonjson
[
  { "countries": ["DE", "AT"], "applicationKey": "eu-checkout", "mode": "COMPLETE" },
  { "stores": ["vip-store"], "applicationKey": "vip-checkout", "mode": "PAYMENT_ONLY" },
  { "applicationKey": "default-checkout", "mode": "PAYMENT_ONLY" }
]
Replace the rules from a filebash
commercetools integration-layer checkout-rules set --file checkout-rules.json --force
At least one rule must remain, so remove refuses to drop the last one. Without a terminal, the commands that ask for confirmation refuse unless you pass --force.

field-visibility

Manage field visibilitybash
commercetools integration-layer field-visibility list [--hidden] [--json]
commercetools integration-layer field-visibility hide --type-key <key> [--space customField|attribute] <field...>
commercetools integration-layer field-visibility show --type-key <key> [--space customField|attribute] <field...> [--force]
commercetools integration-layer field-visibility set --file <path|-> [--force]
Controls which of your custom fields and product attributes a storefront can select. It matches the picker on the Schema tab in the Merchant Center. A hidden field can still be resolved internally, so your extension can read it with @requires. It is absent from the public API schema, so a shopper can neither query nor discover it.
Fields are named by your own identifiers: the key of the custom type or product type, and the name of the field. They are never named by a generated GraphQL name. --space is customField (the default) for a field of a custom type, and attribute for a product attribute.
CommandEffect
listShows every field, grouped by type, as hidden or visible. A rule that does nothing says why.
hideAdds the fields of one type to the hidden set
showRemoves their rules. Asks for confirmation unless you pass --force.
setReplaces the whole hidden set from a JSON file, or from standard input with -. Asks for confirmation unless you pass --force.
show and set make fields publicly selectable, so they ask for confirmation. Without a terminal they refuse unless you pass --force. For a pipeline, keep the set in version control:
Hidden fields filejson
[
  { "space": "customField", "typeKey": "internal-ops", "fieldName": "costPrice" },
  { "space": "attribute", "typeKey": "shoes", "fieldName": "internalCode" }
]
You can write a rule before its field exists. hide notes this and stores the rule, so there is no moment when the new field is public. list shows such a rule as not in force until the field appears.
Every save republishes the schema, and the command waits for the result. It prints The schema was republished. on success. If the rules were stored but the republish failed, a hidden field is still public, so the command exits with code 2. Use Refresh schema on the Schema tab in the Merchant Center to republish. Running hide or show again does not retry, because it finds the rules already stored. set always saves again, so running it again retries the republish.

allowlist

Manage the allowlistbash
commercetools integration-layer allowlist list
commercetools integration-layer allowlist add <host...>
commercetools integration-layer allowlist remove <host...> [--force]
commercetools integration-layer allowlist set <host...> [--force]
The hosts that the sandboxed fetch of your extension may reach. A resolver that calls any other host is refused before the connection opens. Adding the host is therefore a prerequisite for any extension that uses an external service. For an example, see Write Schema Extensions.
A host pattern is either exact, such as api.vendor.com, or a suffix wildcard, such as *.algolia.net. The write commands take several hosts at once. Quote a wildcard, or your shell expands it:
Add hosts to the allowlistbash
commercetools integration-layer allowlist add api.vendor.com '*.algolia.net'
CommandEffect
listPrints the allowed hosts, plus any denials set by the operator
addMerges the given hosts into the existing list
removeDrops the given hosts and keeps the rest. Asks for confirmation unless you pass --force.
setReplaces the entire list with the hosts given. At least one is required. Asks for confirmation unless you pass --force.
remove and set are destructive. Without a terminal they refuse, so a CI run must pass --force.
The operator denylist wins: a host resolves only if it matches the allowlist and does not match the denylist. list shows the denials for information only.

schema fetch

Fetch the core subgraph schemabash
commercetools integration-layer schema fetch [--out <file>]

Prints the core subgraph schema of your Project, which your extension composes against, or writes it to a file. It is useful for editor autocompletion and for seeing what changed.

config

Manage configurationbash
commercetools integration-layer config list
commercetools integration-layer config get <key>
commercetools integration-layer config set <key> <value> [--secret]
commercetools integration-layer config unset <key>
The extension configuration of your Project, which your resolvers read as ctx.config. --secret seals the value: it is encrypted at rest, write-only afterwards, never returned by a read, and never written into your bundle. list and get mask secret values.

Configuration changes take effect on their own. You do not republish the bundle.

Use it in CI

Log in as described in Authenticate in CI, with an API Client that has the manage_project scope. Then push the bundle:
Push in CIbash
EXTENSION_SOURCE_REVISION="$BUILD_ID" \
  commercetools integration-layer extension push --all --wait-timeout 300
  • push waits for the load result by default and exits with a non-zero code on a real failed. A green pipeline therefore means the bundle actually runs, not only that it uploaded. Keep the wait, and raise --wait-timeout for a slow cold start instead.
  • Set EXTENSION_SOURCE_REVISION when the checkout is not a full git working copy, so the recorded revision is your build ID and not nothing.
  • Reserve --force for a coordinated breaking change. It never bypasses the local checks.
  • Commands that ask for confirmation refuse without a terminal, so pass --force to allowlist remove, allowlist set, idp-login delete, checkout-rules remove, checkout-rules set, field-visibility show, and field-visibility set in a pipeline.

More information