**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](https://salesforcecommercecloud.github.io/b2c-developer-tooling/cli/mrt.html) in the Agentic B2C Developer Toolkit.

:::note
Access environment variables in Node.js with [`process.env`](https://nodejs.org/docs/latest/api/process.html#processenv).
:::

## 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](https://salesforcecommercecloud.github.io/b2c-developer-tooling/cli/mrt.html#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

1. Install the B2C CLI or use it from the `@salesforce/b2c-cli` package by following the instructions in [Run the B2C CLI](https://developer.salesforce.com/docs/commerce/commerce-api/guide/b2c-developer-tooling.md#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](https://salesforcecommercecloud.github.io/b2c-developer-tooling/cli/mrt.html#getting-an-api-key).
   - To set up SCAPI authentication for the SCAPI backend and Account Manager scopes, see [SCAPI Authorization](/docs/commerce/b2c-commerce/guide/sfnext-mrt-api.md#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.

:::note
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](/docs/commerce/b2c-commerce/guide/sfnext-mrt-administration.md). 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.
:::

### List All Environment Variables for an Environment

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

```bash
npx @salesforce/b2c-cli mrt env var list --project my-storefront --environment my-environment
```

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

```
Name                                            Value                 Status     Updated
────────────────────────────────────────────────────────────────────────────────────────────────────────
COMMERCE_API_SLAS_SECRET                        ****************mbLs  Completed  10/9/2026, 6:00:20 PM
PUBLIC__app__commerce__api__clientId            ****************941a  Completed  10/9/2026, 6:00:20 PM
PUBLIC__app__commerce__api__organizationId      ****************_013  Completed  10/9/2026, 6:00:20 PM
PUBLIC__app__commerce__api__privateKeyEnabled   ****************      Completed  10/9/2026, 6:00:20 PM
PUBLIC__app__commerce__api__shortCode           ****************-001  Completed  10/9/2026, 6:00:20 PM
PUBLIC__app__commerce__sites                    ****************"]}]  Completed  10/9/2026, 6:00:20 PM
PUBLIC__app__defaultSiteId                      ****************reet  Completed  10/9/2026, 6:00:20 PM
PUBLIC__app__features__shopperContext__enabled  ****************      Completed  10/9/2026, 6:00:20 PM
```

### 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.

```bash
npx @salesforce/b2c-cli mrt env var set "MY_VAR=Hello World" \
  --project my-storefront --environment my-environment
```

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.

```bash
npx @salesforce/b2c-cli mrt env var delete MY_VAR \
  --project my-storefront --environment my-environment
```

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.

```bash
npx @salesforce/b2c-cli mrt env var push \
  --project my-storefront --environment my-environment --file .env
```

## 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](https://salesforcecommercecloud.github.io/b2c-developer-tooling/cli/mrt.html#bundle-commands). To set up authorization for the B2C CLI, see [Set Up the B2C CLI](/docs/commerce/b2c-commerce/guide/sfnext-mrt-cli.md#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.

```bash
npx @salesforce/b2c-cli mrt bundle deploy --storefront my-storefront --environment my-environment --message "Test Release"
```

## See Also

- [Agentic B2C Developer Toolkit: MRT Commands](https://salesforcecommercecloud.github.io/b2c-developer-tooling/cli/mrt.html)
- [Troubleshoot Environment Variables](/docs/commerce/b2c-commerce/guide/sfnext-mrt-env-var-troubleshoot.md)
