Develop Custom SCAPI endpoints for B2C Commerce. Use when creating REST APIs, defining api.json routes, writing schema.yaml (OAS 3.0), or building headless commerce integrations. Covers cartridge structure, endpoint implementation, and OAuth scope configuration.
View on GitHubSalesforceCommerceCloud/b2c-developer-tooling
b2c
skills/b2c/skills/b2c-custom-api-development/SKILL.md
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/main/skills/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.
> **Tip:** If `b2c` CLI is not installed globally, use `npx @salesforce/b2c-cli` instead (e.g., `npx @salesforce/b2c-cli code deploy`).
## 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
```
/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
```
**Important:** API directory names can only contain alphanumeric lowercase characters and hyphens.
## Component 1: API Contract (schema.yaml)
Minimal example:
```yaml
openapi: 3.0.0
info:
version: 1.0.0
title: My Custom API
components:
securitySchemes:
ShopperToken:
type: oauth2
flows:
clientCredentials:
tokenUrl: https://{shortCode}.api.commercecloud.salesforce.com/shopper/auth/v1/organizations/{organizationId}/oauth2/token
scopes:
c_my_scope: My custom scope
parameters:
siteId:
name: siteId
in: query
required: true
schema:
type: string
minLength: 1
paths:
/my-endpoint:
get:
operationId: getMyData
parameters:
- $ref: '#/components/parameters/siteId'
responses:
'200':
description: Suc