Author, run, validate, publish, and inspect Commerce Integration Layer extensions from the terminal.
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.Install
npm install -g @commercetools/cli
commercetools plugins install @commercetools/cli-topic-integration-layer
manage_project scope, as described in Authentication.To check the installed version of the plugin:
commercetools integration-layer --version
Commands that need a login
commercetools auth login, including your Project key and Region. For how to log in, see Authentication.not logged in — run 'commercetools auth login' first and does not attempt the call.| Needs a login | Runs offline |
|---|---|
explore, schema fetch, extension push, extension pull, extension status, extension serve-api-extension, config, allowlist, project-settings, idp-login, checkout-rules, field-visibility | init, extension build, extension invoke-api-extension (local), extension create-api-extension-input, extension serve (standalone) |
Two commands are conditional:
extension validateneeds a login only for its remote checks. Pass--skip remoteto run it fully offline.extension serveneeds 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.
| Edge | Derived host | Serves |
|---|---|---|
| Extensions | https://extensions.integration-layer.{region}.commercetools.com | The routes that need manage_project: the subgraph, extensions, and configuration |
| Experience API | https://graphql.integration-layer.{region}.commercetools.com | The shopper GraphQL API, where operations run |
| Shopper Identity API | https://auth.integration-layer.{region}.commercetools.com | Session minting and the core subgraph that the local gateway routes to |
--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.
| Flag | Environment variable | Purpose |
|---|---|---|
--integration-layer-url | INTEGRATION_LAYER_URL | Base URL of the Extensions edge. Overrides the Region-derived host. |
--project-key | Act on a different Project than the one you are logged in to |
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.
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.commercetools integration-layer init my-extensions
cd my-extensions
pnpm push
--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.--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
commercetools integration-layer init [DIRECTORY] [--template basic] [--force]
Scaffolds an extensions monorepo with:
- A pnpm workspace with the root scripts wired to the
--allflow - Shared TypeScript and ESLint configuration
- One buildable
hello-worldextension underextensions/, with a Vitest test
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 flag | Default | Description |
|---|---|---|
DIRECTORY | . | The directory to scaffold into |
--template | basic | The template. Only basic is available. |
-f, --force | false | Scaffold into a non-empty directory |
extension build
commercetools integration-layer extension build [--entry <file>] [--out <file>] [--all] [--extensions-dir <dir>]
graphql stays external. The command runs offline.| Flag | Default | Description |
|---|---|---|
--entry | src/extension.ts | The extension source file |
--out | dist/extension.js | The output artifact |
--all, --extensions-dir | See One bundle per Project |
extension serve
commercetools integration-layer extension serve [--port 4000] [--entry <file>] [--compose] [--gateway] [--all] [--env-file <path>]
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.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 is | Reaches the Commerce Integration Layer | Extra routes |
|---|---|---|---|
| Default | Your extension subgraph | No, fully offline | None |
--compose | Your extension subgraph | Yes, to fetch the schema | /composed, /schema.graphql, /supergraph.graphql |
--gateway | A federated gateway over your extension and the deployed Commerce Integration Layer | Yes | /_extension |
--all | A gateway over the merged extensions/* subgraph and the Commerce Integration Layer | Yes | /_extension, /composed |
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.pnpm dev --gateway. The root pnpm dev:<example> shortcut only covers the default mode.extension validate
commercetools integration-layer extension validate [--skip local|remote] [--all] [--entry <file>] [--out <file>]
Runs the publish checks without uploading anything, in this order:
| Check | Where | Skippable with --force on push |
|---|---|---|
Static analysis. Rejects use of globals that the sandbox does not provide, such as process, node:*, and eval. | Local | No |
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. | Local | No |
| Composition against the live core subgraph of your Project | Remote | Yes |
| Breaking-change detection against your published schema | Remote | Yes |
--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
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.
| Flag | Default | Description |
|---|---|---|
-f, --force | false | Upload despite failing remote validation. The local checks always fail the command, because a bundle that cannot load is broken whatever you intended. |
--source-revision | Detected from git | The revision to record with the bundle. Environment variable: EXTENSION_SOURCE_REVISION. |
--no-source-revision | false | Push without recording a revision |
--wait, --no-wait | --wait | Wait for the extension runtime to load the pushed version and report back |
--wait-timeout | 180 | Seconds to wait before giving up. The push still stands. |
failed result exits with a non-zero code. Not being able to find out the result never does.pnpm push -- --force. A bare pnpm push --force can be swallowed by pnpm.extension status
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
commercetools integration-layer extension pull [--out <file>] [--force]
./dist with the stored filename.| Flag | Description |
|---|---|
--out | The file to write the bundle to. The default is the stored filename under ./dist. |
-f, --force | Overwrite the output file if it already exists |
extension invoke-api-extension
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>]
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
--keynarrows the run to named handlers.ctx.configcomes fromEXTENSION_CONFIG_*variables, a.envfile, or--env-file, and a--configentry 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.| Flag | Description |
|---|---|
--input | Required. Path to the JSON ExtensionInput. |
--deployed | Send the callback to the deployed extension of the Project. Needs a login. |
--key | Repeatable. Only invoke the handlers with these keys. Local only. |
--all, --extensions-dir | Invoke the merged bundle. Local only. |
--config | Repeatable KEY=VALUE that becomes ctx.config. Local only. |
--env-file | Path to a dotenv file |
--project-key, --integration-layer-url | Override the project or edge of your login. --deployed only. |
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
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
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>]
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:
ngrok http 4000
commercetools integration-layer extension serve-api-extension --public-url https://abc123.ngrok.app
--cleanup. Any tunnel works, for example cloudflared tunnel --url http://localhost:4000.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.
| Flag | Default | Description |
|---|---|---|
--public-url | Required, unless you use --cleanup. The base URL of the tunnel. commercetools calls <public-url>/api-extensions. | |
-p, --port | 4000 | The local port to listen on |
--config | Repeatable KEY=VALUE that becomes ctx.config | |
--all | false | Serve and register the combined bundle of every ./extensions/* package |
--extensions-dir | extensions | The directory that holds the extension packages. Used with --all. |
--cleanup | false | Remove leftover il-localdev-* Extensions and exit without serving |
--env-file | Path 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
commercetools integration-layer extension create-api-extension-input --resource-type <type> [--action Create|Update] [--out <file.json>] [--id <id>]
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.| Flag | Default | Description |
|---|---|---|
--resource-type | Required. The resource type, for example cart. | |
--action | Create | Create or Update. Update samples carry version: 2. |
--out | Write to this file. Without it, the JSON is printed. | |
--id | sample-{resource-type}-id | The resource ID in the sample |
explore
commercetools integration-layer explore [--port 4000] [--deployed] [--as <email>] [--locale <l>] [--currency <c>] [--country <co>]
http://localhost:4000, and proxies every operation to the real endpoint. You paste no tokens and edit no headers.| Flag | Description |
|---|---|
--deployed | Show 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, --country | Presentment values, applied when the session is created. They default to the ones of the Project. |
-p, --port | The local port. Default 4000. |
--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-nameandgraphql-client-versionon 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.shin 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
commercetools integration-layer project-settings get [--json]
commercetools integration-layer project-settings set [--label <text>] [--language <code>] [--currency <code>] [--country <code>]
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.commercetools integration-layer project-settings set --currency EUR --country DE
idp-login
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]
get only reports whether one is set.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.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
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]
| Command | Effect |
|---|---|
get | Prints the rules in match order. remove takes these positions. |
add | Inserts one rule. It appends by default, before an existing catch-all rule. --position places it elsewhere, but never after a catch-all. |
remove | Drops the rule at a position. Asks for confirmation unless you pass --force. |
set | Replaces 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:[
{ "countries": ["DE", "AT"], "applicationKey": "eu-checkout", "mode": "COMPLETE" },
{ "stores": ["vip-store"], "applicationKey": "vip-checkout", "mode": "PAYMENT_ONLY" },
{ "applicationKey": "default-checkout", "mode": "PAYMENT_ONLY" }
]
commercetools integration-layer checkout-rules set --file checkout-rules.json --force
remove refuses to drop the last one. Without a terminal, the commands that ask for confirmation refuse unless you pass --force.field-visibility
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]
@requires. It is absent from the public API schema, so a shopper can neither query nor discover it.--space is customField (the default) for a field of a custom type, and attribute for a product attribute.| Command | Effect |
|---|---|
list | Shows every field, grouped by type, as hidden or visible. A rule that does nothing says why. |
hide | Adds the fields of one type to the hidden set |
show | Removes their rules. Asks for confirmation unless you pass --force. |
set | Replaces 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:[
{ "space": "customField", "typeKey": "internal-ops", "fieldName": "costPrice" },
{ "space": "attribute", "typeKey": "shoes", "fieldName": "internalCode" }
]
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.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
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]
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.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:commercetools integration-layer allowlist add api.vendor.com '*.algolia.net'
| Command | Effect |
|---|---|
list | Prints the allowed hosts, plus any denials set by the operator |
add | Merges the given hosts into the existing list |
remove | Drops the given hosts and keeps the rest. Asks for confirmation unless you pass --force. |
set | Replaces 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.list shows the denials for information only.schema fetch
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
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>
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
manage_project scope. Then push the bundle:EXTENSION_SOURCE_REVISION="$BUILD_ID" \
commercetools integration-layer extension push --all --wait-timeout 300
pushwaits for the load result by default and exits with a non-zero code on a realfailed. A green pipeline therefore means the bundle actually runs, not only that it uploaded. Keep the wait, and raise--wait-timeoutfor a slow cold start instead.- Set
EXTENSION_SOURCE_REVISIONwhen the checkout is not a full git working copy, so the recorded revision is your build ID and not nothing. - Reserve
--forcefor a coordinated breaking change. It never bypasses the local checks. - Commands that ask for confirmation refuse without a terminal, so pass
--forcetoallowlist remove,allowlist set,idp-login delete,checkout-rules remove,checkout-rules set,field-visibility show, andfield-visibility setin a pipeline.
More information
- Commerce Integration Layer overview
- Get started
- Configure and deploy
- Extension authoring guide in the extensions repository, which also has ready-to-edit templates