Developer Preview — This project is in active development. APIs may change. Provide feedback
Skip to content

Authentication Setup

This guide covers setting up authentication for the B2C CLI, including Account Manager API clients, OCAPI permissions, and WebDAV access.

Overview

The CLI uses different authentication mechanisms depending on the operation:

OperationAuth MethodSetup Required
Code deploy, watch (file upload)WebDAV (Basic Auth or OAuth)WebDAV Access
Code list, activate, deleteOAuth + OCAPIAPI Client + OCAPI
Jobs, SitesOAuth + OCAPIAPI Client + OCAPI
SCAPI commands (schemas, custom-apis, eCDN)OAuth + SCAPI scopesAPI Client + SCAPI Scopes
SLAS client managementOAuthAPI Client with appropriate roles
ODS managementOAuthAPI Client with Sandbox API User role
MRT commandsMRT API KeyMRT API Key

TIP

Each CLI command page documents its specific authentication requirements. See the CLI Reference for details.

Account Manager API Client

Most CLI operations require an Account Manager API Client. This is configured in the Salesforce Commerce Cloud Account Manager.

Authentication Methods

The CLI supports two authentication methods:

MethodWhen UsedRole Configuration
User AuthenticationWhen only --client-id is provided (no secret)Roles configured on your user account
Client CredentialsWhen both --client-id and --client-secret are providedRoles configured on the API client

User Authentication opens a browser for interactive login and uses roles assigned to your user account. This is ideal for development and manual operations.

Client Credentials uses the API client's secret for non-interactive authentication. This is ideal for CI/CD pipelines and automation.

Creating an API Client

  1. Log in to Account Manager
  2. Navigate to API Client in the left menu
  3. Click Add API Client
  4. Fill in the required fields:
    • Display Name: A descriptive name (e.g., "B2C CLI")
    • Password: A strong client secret (save this securely for Client Credentials auth)
  5. Configure the Token Endpoint Auth Method:
    • client_secret_post for client credentials flow

Assigning Roles

Roles grant permission to perform specific operations. Roles are configured differently depending on your authentication method.

Understanding Roles and Tenant Filters

Most roles require a tenant filter that specifies which tenants/realms the role applies to. This is configured alongside the role assignment.

RoleOperationsNotes
Salesforce Commerce APISCAPI commands (eCDN, schemas, custom-apis)API Clients only. Requires tenant filter.
Sandbox API UserODS management, SLAS client managementRequires tenant filter with realm/org IDs.
SLAS Organization AdministratorSLAS client management (user auth only)User accounts only. Requires tenant filter.

For Client Credentials (roles on API Client)

Under the API Client's Roles section:

  1. Add roles needed for your operations
  2. For each role, configure the tenant filter with the tenant IDs (e.g., zzxy_prd) or realm IDs you need to access

Important: The Salesforce Commerce API role is currently only available for API Clients, not user accounts.

For User Authentication (roles on User)

In Account Manager, navigate to your user account and add roles. Note that some operations require Client Credentials authentication.

Configuring Scopes

Under Allowed Scopes, add the following scopes based on your needs:

ScopePurpose
mailRequired for user info in authentication flows
rolesCritical - returns role information in the token
tenantFilterCritical - returns tenant access information in the token
openidRequired for OpenID Connect

For SCAPI commands, also add the relevant API scopes:

ScopeCommandsReference
sfcc.cdn-zoneseCDN read operationseCDN Commands
sfcc.cdn-zones.rweCDN write operationseCDN Commands
sfcc.scapi-schemasSCAPI schema browsingSCAPI Schemas
sfcc.custom-apisCustom API statusCustom APIs

Note: Do NOT add SALESFORCE_COMMERCE_API as a scope. This is a role, not a scope.

See the individual CLI command pages for complete scope requirements.

Configuring Tenant Filter

For ODS, SLAS, and SCAPI operations, your API client's roles must have a tenant filter configured:

  1. In Account Manager, go to the API Client settings
  2. Under each role (e.g., Salesforce Commerce API, Sandbox API User), find the Tenant Filter
  3. Add the tenant IDs (e.g., zzxy_prd) or organization IDs you need to access

The tenant filter restricts which tenants/realms the role applies to.

Default Scopes

Under Default Scopes, set scopes that are automatically requested. Recommended configuration:

mail roles tenantFilter openid

These scopes ensure proper authentication and authorization for CLI operations.

Redirect URLs

For User Authentication (implicit flow), configure redirect URLs in your API client:

Redirect URLPurpose
http://localhost:8080Required for B2C CLI user authentication
https://admin.dx.commercecloud.salesforce.com/oauth2-redirect.htmlOptional - enables ODS Swagger interface with same client

Note: Redirect URLs are not required for API clients using only Client Credentials authentication.

OCAPI Configuration

For operations that interact with B2C Commerce instances (code deployment, jobs, sites), you need to configure OCAPI permissions on each instance.

Configuring OCAPI in Business Manager

  1. Log in to Business Manager
  2. Navigate to Administration > Site Development > Open Commerce API Settings
  3. Select the Data API type
  4. Add a configuration for your client ID

Example OCAPI Configuration

json
{
  "_v": "24.5",
  "clients": [
    {
      "client_id": "your-client-id",
      "resources": [
        {
          "resource_id": "/code_versions",
          "methods": ["get"],
          "read_attributes": "(**)",
          "write_attributes": "(**)"
        },
        {
          "resource_id": "/code_versions/*",
          "methods": ["get", "put", "patch", "delete"],
          "read_attributes": "(**)",
          "write_attributes": "(**)"
        },
        {
          "resource_id": "/jobs/*/executions",
          "methods": ["post"],
          "read_attributes": "(**)",
          "write_attributes": "(**)"
        },
        {
          "resource_id": "/jobs/*/executions/*",
          "methods": ["get"],
          "read_attributes": "(**)",
          "write_attributes": "(**)"
        },
        {
          "resource_id": "/job_execution_search",
          "methods": ["post"],
          "read_attributes": "(**)",
          "write_attributes": "(**)"
        },
        {
          "resource_id": "/sites",
          "methods": ["get"],
          "read_attributes": "(**)",
          "write_attributes": "(**)"
        },
        {
          "resource_id": "/sites/*",
          "methods": ["get"],
          "read_attributes": "(**)",
          "write_attributes": "(**)"
        }
      ]
    }
  ]
}

Minimal Configuration by Feature

Code management only:

json
{
  "resource_id": "/code_versions",
  "methods": ["get"]
},
{
  "resource_id": "/code_versions/*",
  "methods": ["get", "put", "patch", "delete"]
}

Job execution only:

json
{
  "resource_id": "/jobs/*/executions",
  "methods": ["post"]
},
{
  "resource_id": "/jobs/*/executions/*",
  "methods": ["get"]
},
{
  "resource_id": "/job_execution_search",
  "methods": ["post"]
}

Site listing only:

json
{
  "resource_id": "/sites",
  "methods": ["get"]
},
{
  "resource_id": "/sites/*",
  "methods": ["get"]
}

SCAPI Authentication

SCAPI commands (eCDN, SCAPI schemas, custom APIs) require OAuth authentication with specific roles and scopes.

Required Setup

  1. Role: Assign the Salesforce Commerce API role to your API client with appropriate tenant filter
  2. Scopes: Add required SCAPI scopes to your API client's Allowed Scopes

Scopes by Command

CommandRequired ScopeReference
b2c scapi schemas list/getsfcc.scapi-schemasSCAPI Schemas
b2c scapi custom statussfcc.custom-apisCustom APIs
b2c ecdn (read operations)sfcc.cdn-zoneseCDN
b2c ecdn (write operations)sfcc.cdn-zones.rweCDN

The CLI automatically requests these scopes. Your API client must have them in the Allowed Scopes list.

TIP

For detailed authentication requirements including specific scopes for each command, see the individual CLI command reference pages.

Configuration

bash
# Set credentials
export SFCC_CLIENT_ID=my-client
export SFCC_CLIENT_SECRET=my-secret
export SFCC_TENANT_ID=zzxy_prd
export SFCC_SHORTCODE=kv7kzm78

# Example: List SCAPI schemas
b2c scapi schemas list

WebDAV Access

WebDAV is required for file upload operations (code deploy, code watch, webdav commands).

Use your Business Manager username and a WebDAV access key. This provides better performance for file operations.

  1. In Business Manager, go to Administration > Organization > Users
  2. Select your user
  3. Generate or view your WebDAV Access Key

See Configure WebDAV File Access for detailed instructions.

bash
export SFCC_USERNAME=your-bm-username
export SFCC_PASSWORD=your-webdav-access-key

Option B: OAuth-based WebDAV

If you prefer to use OAuth credentials for WebDAV (instead of basic auth), you must configure WebDAV Client Permissions:

  1. Log in to Business Manager
  2. Navigate to Administration > Organization > WebDAV Client Permissions
  3. Add a JSON configuration for your API client ID:
json
{
  "clients": [
    {
      "client_id": "your-client-id",
      "permissions": [
        { "path": "/cartridges", "operations": ["read_write"] },
        { "path": "/impex", "operations": ["read_write"] },
        { "path": "/logs", "operations": ["read_write"] }
      ]
    }
  ]
}

Common paths for CLI operations:

PathOperations
/cartridgesCode deployment
/impexSite import/export
/logsLog file access
/catalogs/<catalog-id>Catalog file access
/libraries/<library-id>Content library access

Note: This configuration is only needed when using OAuth for WebDAV. It is not required when using basic authentication with username/access key.

Managed Runtime API Key

MRT commands use a separate API key system.

Getting an MRT API Key

  1. Log in to the Managed Runtime dashboard
  2. Navigate to Account Settings > API Keys
  3. Click Create API Key
  4. Copy and save the key securely (it's only shown once)

Configuring the API Key

bash
# Environment variable
export SFCC_MRT_API_KEY=your-mrt-api-key

# Or in ~/.mobify config file
echo '{"api_key": "your-mrt-api-key"}' > ~/.mobify

Quick Start Example

Here's a complete example for setting up CLI access:

1. Create API Client in Account Manager

  1. Log in to Account Manager
  2. Navigate to API Client > Add API Client
  3. Configure:
    • Display Name: B2C CLI
    • Password: Generate a strong secret (save securely)
    • Roles:
      • Salesforce Commerce API - add tenant filter with your tenant IDs
      • Sandbox API User - if using ODS (add tenant filter)
    • Allowed Scopes: mail roles tenantFilter openid sfcc.cdn-zones
    • Default Scopes: mail roles tenantFilter openid
    • Redirect URLs: http://localhost:8080 (for user authentication)

2. Configure OCAPI (for code list/activate/delete, jobs, sites)

Add the JSON configuration shown in OCAPI Configuration to enable code version and job APIs.

3. Configure WebDAV Access (for code deploy/watch, webdav commands)

Either:

  • Use your BM username + WebDAV access key (recommended), or
  • Configure WebDAV Client Permissions for OAuth

4. Set Environment Variables

bash
# OAuth credentials
export SFCC_CLIENT_ID=your-client-id
export SFCC_CLIENT_SECRET=your-client-secret

# Instance (for OCAPI commands)
export SFCC_SERVER=your-instance.demandware.net

# SCAPI (for eCDN, schemas, custom-apis)
export SFCC_TENANT_ID=zzxy_prd
export SFCC_SHORTCODE=kv7kzm78

# WebDAV (if using BM credentials)
export SFCC_USERNAME=your-bm-username
export SFCC_PASSWORD=your-webdav-access-key

5. Test the Configuration

bash
# Test OAuth + OCAPI
b2c code list

# Test WebDAV
b2c webdav ls --root=cartridges

# Test SCAPI
b2c scapi schemas list

Troubleshooting

"Unauthorized" errors

  • Verify your client ID and secret are correct
  • Check that OCAPI is configured for your client ID
  • Ensure the API client has the required roles

"Forbidden" on WebDAV operations

  • Check WebDAV Client Permissions in Business Manager
  • Verify your WebDAV access key is correct
  • Ensure the folder you're accessing is permitted

"Invalid scope" errors

  • Add the required scopes to your API client's Allowed Scopes
  • For SCAPI commands, ensure the relevant sfcc.* scopes are in Allowed Scopes
  • Verify Default Scopes includes mail roles tenantFilter openid

Next Steps

Released under the Apache-2.0 License.