Guide for developing SCAPI Custom APIs on Salesforce B2C Commerce
View on GitHubSalesforceCommerceCloud/b2c-developer-tooling
b2c
plugins/b2c/skills/b2c-custom-api-development/SKILL.md
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/main/plugins/b2c/skills/b2c-custom-api-development/SKILL.md -a claude-code --skill b2c-custom-api-developmentInstallation paths:
.claude/skills/b2c-custom-api-development/# Custom API Development Skill
This skill guides you through developing Custom APIs for Salesforce B2C Commerce. Custom APIs let you expose custom script code as REST endpoints under the SCAPI framework.
## Overview
A Custom API URL has this structure:
```
https://{shortCode}.api.commercecloud.salesforce.com/custom/{apiName}/{apiVersion}/organizations/{organizationId}/{endpointPath}
```
Three components are required to create a Custom API:
1. **API Contract** - An OAS 3.0 schema file (YAML)
2. **API Implementation** - A script using the B2C Commerce Script API
3. **API Mapping** - An `api.json` file binding endpoints to implementations
## Cartridge Structure
Custom APIs are defined within cartridges. Create a `rest-apis` folder in the cartridge directory with subdirectories for each API:
```
/my-cartridge
/cartridge
package.json
/rest-apis
/my-api-name # API name (lowercase alphanumeric and hyphens only)
api.json # Mapping file
schema.yaml # OAS 3.0 contract
script.js # Implementation
/scripts
/controllers
```
**Important:** API directory names can only contain alphanumeric lowercase characters and hyphens.
## Component 1: API Contract (schema.yaml)
The API contract defines endpoints using OAS 3.0 format:
```yaml
openapi: 3.0.0
info:
version: 1.0.0 # API version (1.0.0 becomes v1 in URL)
title: My Custom API
components:
securitySchemes:
ShopperToken: # For Shopper APIs (requires siteId)
type: oauth2
flows:
clientCredentials:
tokenUrl: https://{shortCode}.api.commercecloud.salesforce.com/shopper/auth/v1/organizations/{organizationId}/oauth2/token
scopes:
c_my_scope: Description of my scope
AmOAuth2: # For Admin APIs (no siteId)
type: oauth2
flows:
clientCredentials