---
schema_version: "1"
id: 3eae2bd02db70e86ffcf60bb65540a8dbf16ec61400f936a98dfac2793feddd3
title: Automate Storefront Administration Tasks with the B2C CLI
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/sfnext/guides/sfnext-mrt-cli.md
canonical_url: https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/sfnext-mrt-cli.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 67b0ebf2a63ec23e379382541a3e39d67af750ce3d283d68dc7ab2e2e943855d
products:
  - Composable Storefront
  - Salesforce APIs
---
**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.html#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 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](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](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/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 `staging` as the project and environment. Replace them with the actual values for your storefront. To get the project ID, see [Find a Project](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/sfnext-mrt-administration.md).

### 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 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.

```bash
npx @salesforce/b2c-cli mrt env var set "MY_VAR=hello world" \
  --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.

```bash
npx @salesforce/b2c-cli mrt env var delete MY_VAR \
  --project my-storefront --environment staging
```

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 staging --file .env
```

**note:** 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.

## 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](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/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 `staging` with your project ID and environment.

```bash
npx @salesforce/b2c-cli mrt bundle deploy -p my-storefront -e staging --message "Test Release"
```

The `--storefront` argument is an alias for the `-p` project ID argument, which is also the storefront ID.

```bash
npx @salesforce/b2c-cli mrt bundle deploy --storefront my-storefront -e staging --message "Test Release"
```

## See Also

- [Agentic B2C Developer Toolkit: MRT Commands](https://salesforcecommercecloud.github.io/b2c-developer-tooling/cli/mrt.html)
- [Troubleshoot Environment Variables](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/sfnext-mrt-env-var-troubleshoot.md)
