Use the B2C Commerce API (SCAPI) to automate the end-to-end storefront development workflow. The SCAPI Account Manager-based authorization is suitable for automation with a bot user. Create a Storefront Next storefront, generate code locally, and upload and deploy a bundle to a Managed Runtime (MRT) environment. A storefront created with SCAPI appears in Business Manager. The creation process provisions the Account Manager API client, the Shopper Login and API Access Service (SLAS) client, an MRT project and environment, and configures eCDN.
Prerequisites
A B2C Commerce instance and a site for the storefront.
Permissions to create storefronts in Business Manager, plus the Managed Runtime User or Managed Runtime Admin role in Account Manager.
The curl command-line tool.
An Account Manager API client with access to the target B2C Commerce instance and specific scopes.
1. Configure SCAPI Authorization
Accessing each storefront API family requires OAuth2 authorization and setting up specific scopes in Account Manager.
Ask an administrator with the API Administrator role in Account Manager to create an Account Manager API client with the scopes required to access the storefront APIs. See Authorization for SCAPI Admin APIs. Use these scopes for each API family in the allowed scopes section. By default, each scope grants read-only access if you don’t specify .rw in the scope name. Append .rw to grant read and write access.
sfcc.storefront.storefronts[.rw]: Access to storefronts. Grant write access for creating, editing, and deleting a storefront.
sfcc.storefront.environments[.rw]: Access to environments and environment variables. Grant write access for creating and deleting environments, editing environment settings, and creating, editing, and deleting environment variables.
sfcc.storefront.deployments[.rw]: Access to deployments. Grant write access for uploading bundles and deploying them.
Set shell variables for your Account Manager client and B2C Commerce instance. Replace the placeholder values from your B2C Commerce instance. The realm ID and instance ID form the tenant scope, for example, zzte_053. To find these values, see Base URL and Request Formation.
1export "SFCC_OAUTH_CLIENT_ID=your-account-manager-client-id"2export "SFCC_OAUTH_CLIENT_SECRET=your-account-manager-client-secret"3export "SFCC_CREDENTIALS=${SFCC_OAUTH_CLIENT_ID}:${SFCC_OAUTH_CLIENT_SECRET}"4export "SFCC_REALM_ID=b2c_realm"5export "SFCC_INSTANCE_ID=b2c-instance-id"6export "SFCC_OAUTH_SCOPES=list of scopes separated by space"
Request an access token for OAuth2 authorization from Account Manager. This curl command calls the access token endpoint and passes the Account Manager client ID values and the B2C Commerce instance values. The access token request includes the Salesforce Commerce API tenant scope for your B2C Commerce instance and the storefront API scopes.
The response returns the access token in the "access_token" field.
Store the returned token in a shell variable to use in the next SCAPI requests.
1export SCAPI_TOKEN='Insert_Access_Token'
2. Create the Storefront with SCAPI
Create the Storefront Next storefront. Replace the placeholder values with valid values for your B2C Commerce instance: {shortCode}, and {organizationId}. Replace My-Storefront with the storefront name. The organization ID has the format f_ecom_{realm}_{instance}. This endpoint creates a storefront with the default Retail Next (fashion) template.
The create request is asynchronous and returns HTTP 202 Accepted. The response contains the storefront ID in the "storefrontId" field and the setup status in the "setupStatus" field, among other things. This response shows an example.
Save the returned storefront ID in a shell variable to use for the next call.
1export STOREFRONT_ID='returned-storefront-ID'
Storefront setup can take up to 30 minutes. Poll the storefront to check its status. The status is returned in the "setupStatus" field. Keep polling until setup completes. If setup completes successfully, the status field is "setupStatus":"success". Use this request to get the storefront status. Replace {storefrontId} with the storefront ID that the create request returned.
1curl "https://{shortCode}.api.commercecloud.salesforce.com/storefront/storefronts/v1/organizations/{organizationId}/storefronts/{storefrontId}" \2 -X GET \3 -H "Authorization: Bearer $SCAPI_TOKEN"
This response shows an example status that the request returns while the storefront is still in progress.
After the storefront is created, it appears in Business Manager, in Administration > Storefronts.
(Optional) Get the Environment File from Business Manager
The .env file contains B2C Commerce instance information, Managed Runtime project and environment IDs, and auto-generated API client resources, including the SLAS client ID, which is used to access B2C Commerce Shopper Login APIs. Download the .env file from Business Manager.
Instead of downloading and copying the contents of the .env file, replace the values in the generated storefront .env file in the next step.
Note
Log in to Business Manager. In the App Launcher, go to Administration > Storefronts, and click your newly created storefront.
On the storefront detail page, click Download .env to download the .env file.
3. Build the Local Storefront Code
In a directory where you keep local storefront projects, run the Storefront Next generator. Replace My-Storefront with the storefront name you chose in the create request. The storefront name is different than the storefront ID that the create request returns.
After the command completes, a new folder is created for the storefront.
If you downloaded the .env file from Business Manager:
Open the .env file and copy its contents.
In your storefront folder, open the .env file and replace its contents with the copied contents.
If you didn’t download the .env file from Business Manager, replace the values in the generated storefront .env file. To create a SLAS client, use the B2C CLI. See SLAS Commands in the Agentic B2C Developer Toolkit.
Change to the project directory and install its dependencies, then run a build.