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.
Note
Point the CLI to the API Backend
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.
Set Up the B2C CLI
Install the B2C CLI or use it from the @salesforce/b2c-cli package by following the instructions in Run the B2C CLI.
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 which API backend you want the CLI 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.
Manage Environment Variables with the B2C CLI
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 staging as the project and environment. Replace them with the actual values for your storefront. To get the project ID, see Find a Project.
Note
List All Environment Variables for an Environment
Use this command to list the environment variables for a storefront and environment.
1npx @salesforce/b2c-cli mrt env var list --project my-storefront --environment staging
Set or Update an Environment Variable
Use the mrt env var set command to create an environment variable for a storefront and environment with the specified value.
1npx @salesforce/b2c-cli mrt env var set "MY_VAR=hello world" \2 --project my-storefront --environment staging
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.
Create Environment Variables from an .env File
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.
When you add a new environment variable, wait for the redeploy of the bundle to complete, and then deploy a new bundle that uses the new variable.
Note
Create and Deploy Bundles with the B2C CLI
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 staging with your project ID and environment.