Applies to: Storefront Next and Composable Storefront

Automate Storefront Administration Tasks with the B2C CLI

Use the B2C CLI to create environments and environment variables and to deploy bundles. Do these tasks in the CLI rather than in Business Manager or Runtime Admin. The CLI streamlines your storefront development lifecycle. See MRT Commands in the Agentic B2C Developer Toolkit.

Access environment variables in Node.js with process.env.

By default, the CLI calls Managed Runtime API. Some commands, including b2c mrt bundle and b2c mrt env var, can call SCAPI and authorize with an Account Manager API client. See SCAPI-supported commands. To point the CLI to an API backend, add the --mrt-backend argument and one of these values.

  • --mrt-backend scapi uses SCAPI.
  • --mrt-backend legacy uses Managed Runtime API.
  • --mrt-backend auto uses SCAPI when its prerequisites are detected. Otherwise, the CLI uses Managed Runtime API. If a SCAPI request fails with a safe pre-execution error, the CLI falls back to Managed Runtime API.
  1. Install the B2C CLI or use it from the @salesforce/b2c-cli package by following the instructions in Run the B2C CLI.
  2. Set up the authorization for the B2C CLI. For the environment variable examples in this page, set up SCAPI or the MRT API key authorization depending on which API backend you want to use.
    • To set up MRT API key for the Managed Runtime API backend, see Getting an API Key.
    • To set up SCAPI authentication for the SCAPI backend and Account Manager scopes, see SCAPI Authorization.

Use the B2C CLI to list all environment variables for an environment, update an environment variable value, and create environment variables from an environment file.

A storefront in Business Manager corresponds to a project in Managed Runtime. The examples use my-storefront and my-environment as the project and environment. Replace them with the actual values for your storefront. To get the project ID, see Find a Project. If the storefront project .env file defines the storefront ID in MRT_PROJECT and environment ID in MRT_TARGET, you can omit the corresponding --project, -p, or --storefront arguments and the --environment or -e argument from the commands.

Use this command to list the environment variables for a storefront and environment.

The command returns a list of environment variables with their values masked. For example:

Use the mrt env var set command to create an environment variable for a storefront and environment with the specified value.

Environment variable operations are asynchronous. The status of the variable first shows as Pending when you create the variable. After the creation process completes, the status becomes Completed.

To remove a variable, use delete. Setting MY_VAR=null with the CLI stores the text null instead of removing the variable.

When you modify environment variables, the environment redeploys. Updated values are available when the redeploy completes.

Use this command to create environment variables from the .env file created during storefront setup in Business Manager. To skip the confirmation prompt, add the --yes argument.

Use the mrt bundle commands to create and deploy bundles to an environment. For the deployment commands, see Bundle Commands. To set up authorization for the B2C CLI, see Set Up the B2C CLI.

This example creates and deploys the bundle for a storefront and environment. Replace my-storefront and my-environment with your project ID and environment. The --storefront argument is an alias for the -p or --project project ID argument, which is also the storefront ID. The CLI queues the deployment and runs it asynchronously. To wait for the deployment to finish, add the --wait argument.