# Deploy Storefront Next to Managed Runtime (MRT)

To redeploy a storefront that was created in Business Manager after initial deployment, use the Storefront Next CLI and the autocreated MRT project and environment. Deploy a storefront with a user-based MRT API key or SCAPI Account Manager authorization.

:::note
If using the Developer Workspace beta, see [Deploy Bundles in Business Manager (Beta)](#deploy-bundles-in-business-manager-beta).
:::

## Prerequisites

- Node Package Manager (pnpm) version 10.28.0 or later. See [Installation](https://pnpm.io/installation) on the pnpm site.
- Node.js version 24.13.0 or later. See [Download Node.js](https://nodejs.org/en/download) on the Node.js site.
- To install Storefront Next dependencies specified in `package.json`, run the `pnpm install` command.
- To save the MRT API key credentials using the B2C CLI, install the B2C CLI. See [Agentic B2C Developer Toolkit](https://salesforcecommercecloud.github.io/b2c-developer-tooling/guide/).

## Get the Storefront and Environment IDs

1. In Business Manager, navigate to your storefront. Click App Launcher ![App Launcher](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/sfnext/shared/appLauncher.png), then select **Administration > Sites > Storefronts**, and click your storefront.
2. In the storefront detail page, click your environment, and then next to Deployments, click **Manage**.
3. If you have an `.env` file in your storefront with the project ID (`MRT_PROJECT`) and environment ID (`MRT_TARGET`), skip this step. Otherwise, get these values from [Runtime Admin](https://runtime.commercecloud.com/).

   a. To get the environment ID, click **Environment Settings**, and copy the Environment ID value.

   b. To get the project ID, click the project name, then **Project Settings**, and copy the Project ID value.

## Deploy Using MRT API Key Authorization

1. To authenticate the CLI to Managed Runtime, use an API key. Get the Managed Runtime API key in Managed Runtime Admin. In Account Settings, under Personal API Key:

   a. If you haven't yet created an API key, click **Generate**.

   b. If you already have an API key, the value is partially masked. Click **Reset**, then click **Reset my API Key** when asked for confirmation.

   c. Run this command to save the API key locally in the `~/.mobify` file so it can be reused whenever you run the `pnpm sfnext push` command. Replace the placeholder values in this command before running it.

   ```
   b2c mrt save-credentials --user {your-email@example.com} --api-key {your-mrt-api-key}
   ```

   :::note
   We recommend saving the MRT API key credentials. If you don't save the MRT API key, you can add the API key in the `MRT_API_KEY` variable in the `.env` file or supply it in the `--api-key` argument on the command line. See [MRT API Key](https://salesforcecommercecloud.github.io/b2c-developer-tooling/guide/configuration.html#mrt-api-key) in the Agentic B2C Developer Toolkit.
   :::

2. From your local storefront folder, use this command to create a bundle and deploy it to your Managed Runtime environment. Replace the placeholders with the MRT project ID and target environment.

   ```
   pnpm sfnext push --project {mrt-project-id} --environment {target-env}
   --message "Deploying quick start bundle."
   ```

   :::tip
   Always run `pnpm sfnext push` from the local storefront folder. To run the push command from another folder outside your storefront, use `pnpm dlx @salesforce/storefront-next-dev push` instead and pass in the storefront folder path with `--project-directory {sfnext-project-folder}`.
   :::

   :::note
   The `.env` file in your Storefront Next project folder contains environment variables that the Storefront Next CLI uses. You can set the project ID in the `MRT_PROJECT` variable and the target environment in the `MRT_TARGET` variable. If you specify these values in both the command line and the `.env` file, the command line arguments are used.
   :::

3. Verify that the bundle was deployed to the target environment. In Managed Runtime Admin, in Projects, click your project and then your environment.

## Deploy Using SCAPI Authorization

1. Set up an Account Manager API client with the storefront-specific scopes. See [Automate Storefront Administration with APIs](/docs/commerce/b2c-commerce/guide/sfnext-mrt-api.md#scapi-authorization). Note the Account Manager client ID and client secret (password) because you use them in the next step.

2. Specify the B2C Commerce and MRT configurations in the local `.env` file for the sfnext CLI command to use. The Account Manager client that the Business Manager storefront setup creates doesn't contain the scopes for the storefront, so be sure to specify the Account Manager client you created. To get B2C Commerce settings, go to **Administration > Site Development > Salesforce Commerce API Settings**.

   - `SFCC_OAUTH_CLIENT_ID`=Insert_Account_Manager_Client_Id
   - `SFCC_OAUTH_CLIENT_SECRET`=Insert_Account_Manager_Client_Secret
     These values are populated when you generate the storefront code using the CLI.
   - `PUBLIC__app__commerce__api__organizationId`=f_ecom_realm_instance
   - `MRT_PROJECT`=Insert_project_Id
   - `MRT_TARGET`=Insert_environment_Id

   :::note
   If you don't specify these configuration values in the `.env` file, pass them as command-line arguments for the `pnpm sfnext push` command: `--client-id`, `--client-secret`, `--tenant-id`, `--short-code`, `--project`, and `--environment`.
   :::

3. From your local storefront folder, use this command to create a bundle and deploy it to the Managed Runtime environment. Replace the placeholders with the MRT project ID and target environment. The `--mrt-backend scapi` argument tells the CLI to use SCAPI for the deployment.

   ```
   pnpm sfnext push --mrt-backend scapi --wait --message "Deploying quick start bundle."
   ```

   :::tip
   Always run `pnpm sfnext push` from the local storefront folder. To run the push command from another folder outside your storefront, use `pnpm dlx @salesforce/storefront-next-dev push` instead and pass in the storefront folder path with `--project-directory {sfnext-project-folder}`.
   :::

4. Verify that the bundle was deployed to the target environment. In Managed Runtime Admin, in Projects, click your project and then your environment.

## Deploy Bundles in Business Manager (Beta)

If your B2C org is enrolled in the Developer Workspace beta, deploy new bundles from Business Manager and track the deployment progress and history. Before deploying a bundle, create it by following the steps in this page.

To only upload a bundle and not deploy it, omit the `--environment` argument from the CLI command and remove the `MRT_TARGET` variable from the `.env` file. Find the project ID in the downloaded `.env` file from the storefront detail page in Business Manager, or in the Complete Your Storefront task.

```
pnpm sfnext push --project {mrt-project-id} --message "Deploy retail storefront v1.0.0"
```

When this command completes, the bundle is uploaded and appears in Business Manager in **Administration > Storefronts > *Your Storefront* > Bundles**. Deploy it by clicking **Deploy** and selecting the environment.

![The deployed bundle is displayed in the target environment page](https://a.sfdcstatic.com/developer-website/sfdocs/commerce-cloud/media/sfnext/sfnext-bundles.png)

To upload and deploy in one step, specify the environment ID in the `--environment` argument or in the `MRT_TARGET` variable in the `.env` file. The `--wait` argument waits for the deployment to complete before the command exits.

```
pnpm sfnext push --project {mrt-project-id} --environment {environment-id} --wait --message "Deploying quick start bundle."
```

## Create and Deploy Bundles via the B2C CLI

Use the `mrt bundle` commands to create and deploy bundles to an environment. See [Automate Storefront Administration Tasks with the B2C CLI](/docs/commerce/b2c-commerce/guide/sfnext-mrt-cli.md).

## See Also

- [CLI Reference](/docs/commerce/b2c-commerce/guide/sfnext-cli.md)
- [Agentic B2C Developer Toolkit: Storefront Next](https://salesforcecommercecloud.github.io/b2c-developer-tooling/guide/storefront-next.html)
- [Agentic B2C Developer Toolkit: Resolution Priority](https://salesforcecommercecloud.github.io/b2c-developer-tooling/guide/configuration.html#resolution-priority)
- [Manage the Storefront Development Workflow in Business Manager (Beta)](/docs/commerce/b2c-commerce/guide/sfnext-developer-workspace.md)
