---
schema_version: "1"
id: 3c8ade117301fbcacb7bc30ca93f9245151a1cb53810d6499a40fa2449b9d46f
title: Automate Storefront Administration with APIs
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/sfnext/guides/sfnext-mrt-api.md
canonical_url: https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/sfnext-mrt-api.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6cd95b8b56e929ed52bca662735c679ef759817188b48eb79d1a5b3160834b6f
products:
  - Composable Storefront
  - Salesforce APIs
---
**Applies to: Storefront Next and Composable Storefront**

# Automate Storefront Administration with APIs

Perform automated storefront administration and development tasks to streamline your storefront development lifecycle and CI/CD. Using the API, create a storefront, update, edit, and delete storefronts. Create and manage environments, environment variables, access control headers, and redirects. Also, upload bundles and start deployments. Use one of two APIs: B2C Commerce (SCAPI) or Managed Runtime (MRT) API. We recommend you use SCAPI for automation based on a bot user. Also, use SCAPI to create and edit storefronts, and edit environment settings, which are not available in the MRT API.

**note:** Creating a storefront is currently available for Storefront Next only and isn't supported for Composable Storefront.

## Administer Your Storefront with SCAPI

SCAPI offers ease of setup because you use the same Account Manager API authorization as other SCAPI endpoints that you're already familiar with for other API administration tasks. You don't need to create a separate Managed Runtime API key. The authorization mechanism used in SCAPI enables using a bot user for full automation.

These API families are available for managing the storefront resources.

- [B2C Commerce API: Storefronts](https://developer.salesforce.com/docs/commerce/commerce-api/references/storefronts?meta=Summary)
- [B2C Commerce API: Environments](https://developer.salesforce.com/docs/commerce/commerce-api/references/environments?meta=Summary)
- [B2C Commerce API: Deployments](https://developer.salesforce.com/docs/commerce/commerce-api/references/deployments?meta=Summary)

## SCAPI Authorization

Accessing each storefront API family requires OAuth2 authorization and setting up specific scopes in Account Manager.

1. Create an Account Manager API client with the scopes required to access the storefront APIs. See [Authorization for SCAPI Admin APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/authorization-for-admin-apis.html). These are the scopes you need per API family.
   - `sfcc.storefront.storefronts.rw`: Read and write access to storefronts. Write access is needed to create, edit, or delete a storefront.
   - `sfcc.storefront.environments.rw`: Read and write access to environments and environment variables. Write access is needed to create and delete environments, edit environment settings, and create, edit, and delete environment variables.
   - `sfcc.storefront.deployments.rw`: Read and write access to deployments. Write access is needed to upload bundles and deploy them.
2. Request an access token to use for OAuth2 authorization.

## Example SCAPI Requests

Here are examples of common tasks. Configure the correct scope in Account Manager for each API family. See [SCAPI Authorization](#scapi-authorization). For all API requests that you can make, see the API reference.

These examples use the `curl` tool to send API requests. For more information, see [Curl](https://curl.se/).

### Create a Storefront Next Store

```
curl "https://{shortCode}.api.commercecloud.salesforce.com/storefront/storefronts/v1/organizations/{organizationId}/storefronts" \
  -X POST \
  -H "content-type: application/json" \
  -d '{
  "storefrontName": "MarketStreet",
  "type": "storefront_next",
  "sites": [
    "MarketStreet"
  ]
}'
```

For a full description, see [createStorefront](https://developer.salesforce.com/docs/commerce/commerce-api/references/storefronts?meta=createStorefront).

### Create an Environment

```
curl "https://{shortCode}.api.commercecloud.salesforce.com/storefront/environments/v1/organizations/{organizationId}/storefronts/{storefrontId}/environments" \
  -X POST \
  -H "content-type: application/json" \
  -d '{
  "displayName": "Production"
}'
```

For a full description, see [createEnvironmentForStorefront](https://developer.salesforce.com/docs/commerce/commerce-api/references/environments?meta=createEnvironmentForStorefront).

### Create an Environment Variable

The endpoint for creating an environment variable is common for updating and deleting environment variables. All use the PATCH method.

```
curl "https://{shortCode}.api.commercecloud.salesforce.com/storefront/environments/v1/organizations/{organizationId}/storefronts/{storefrontId}/environments/{environmentId}/environment-variables" \
  -X PATCH \
  -H "content-type: application/json" \
  -d '{
  "MAX_CART_ITEMS": {
    "value": 50
  },
  "PAYMENT_GATEWAY_API_KEY": {
    "value": "sk_live_a1b2c3d4e5f6"
  },
  "LEGACY_CHECKOUT_URL": {
    "value": null
  }
}'
```

For a full description, see [updateEnvironmentVariables](https://developer.salesforce.com/docs/commerce/commerce-api/references/environments?meta=updateEnvironmentVariables).

### Upload a Bundle

```
curl "https://{shortCode}.api.commercecloud.salesforce.com/storefront/deployments/v1/organizations/{organizationId}/storefronts/{storefrontId}/bundles" \
  -X POST \
  -H "content-type: multipart/form-data" \
  -d '"bundle": "<binary .tar.gz archive, e.g. storefront-bundle.tar.gz>"
"message": "Release 2.1.0"
"rootDir": "bld"
"configPath": ".mrt/config.json"
"matchMode": "strict"'
```

For a full description, see [uploadBundleForStorefront](https://developer.salesforce.com/docs/commerce/commerce-api/references/deployments?meta=uploadBundleForStorefront).

## Managed Runtime API

Use the Managed Runtime API to automate the administration tasks in your app. The API offers similar capabilities to SCAPI but requires a different authorization mechanism and doesn't support creating storefronts. It precedes SCAPI and is based on Runtime Admin resources. Managed Runtime API is available for Storefront Next and Composable Storefront. To learn more, see [Managed Runtime API](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guides/using-the-managed-runtime-api.md).

## Read-Only Mode During Maintenance

During planned maintenance windows, the Managed Runtime API rejects write requests (POST, PUT, PATCH, and DELETE) with an HTTP `503 Service Unavailable` response and error code `service_read_only`. Read requests (GET) continue to work normally. Retry write requests after the maintenance window concludes.
