Zum Inhalt springen

OCAPI / SCAPI

OCAPI-Clients müssen im Commerce Cloud Account Manager registriert werden, bevor du OAuth-Tokens nutzen kannst. So legst du einen Client an:

  1. Login & Navigation
  2. Basisdaten (Name + Secret)
    • Display Name vergeben (sprechend, z. B. „SCAPI Admin – CI Pipeline“)
    • Password setzen + bestätigen (client secret)
    • Secret sicher speichern (Passwortmanager)
  3. Organization zuordnen
    • Abschnitt OrganizationsAdd → deine Org(s) auswählen → Add klicken
  4. Rollen zuweisen (für OCAPI und SCAPI unterschiedlich)
    • SCAPI
      • Abschnitt RolesAdd
      • In der Kategorie Salesforce Commerce API die Rolle Salesforce Commerce API auswählen → Add
      • Danach per Filter die Organization auswählen und die Instances hinzufügen, die der Client bedienen darf
    • OCAPI
      • keine Rolle zuweisen
      • OCAPI-Berechtigung passiert später in Business Manager
  5. Token Endpoint Auth Method
    • client_secret_post auswählen
  6. Speichern
    • Save klicken
  1. Business Manager öffnen
    Melde dich im Business Manager deiner Sandbox an.

  2. Open Commerce API Settings
    Navigiere zu AdministrationSite DevelopmentOpen Commerce API Settings.

  3. API-Einstellungen pro Shop konfigurieren

    • Wähle die gewünschte Site (z. B. RefArch oder deine Storefront-Site).
    • Setze Enable OCAPI auf Enabled.
    • Lege die erlaubten OCAPI-Versionen fest (z. B. v22_10, v23_5 je nach Bedarf).
    • Speichere die Änderungen.
  4. Rollen und Berechtigungen Der im Account Manager angelegte OCAPI-Client nutzt die zugewiesenen API-Rollen. Stelle sicher, dass die Rolle z. B. Shop API – Read/Write (oder nur Read) für die gewünschten Ressourcen hat.

  5. Token-URL und Basis-URL

    • Token-URL (Auth): https://<realm>.auth.<region>.commercecloud.salesforce.com/oauth/token
    • OCAPI-Basis-URL (Data): https://<realm>-api.commercecloud.salesforce.com/site/<siteId>/ Ersetze <realm>, <region> und <siteId> durch deine Werte (z. B. aus Account Manager / Business Manager).
AttributBedeutung
_vFür welche OCAPI Versionen gültig
client_idWelcher API Client darf zugreifen
resource_idWelche API Ressource erlaubt ist
methodsWelche HTTP Methoden erlaubt sind
read_attributesWelche Felder gelesen werden dürfen
write_attributesWelche Felder geschrieben werden dürfen
{
"_v": "26.2",
"clients": [
{
"client_id": "YOUR_CLIENT_ID_HERE",
"resources": [
{
"resource_id": "/product_search",
"methods": ["get"],
"read_attributes": "(**)"
},
{
"resource_id": "/products/*",
"methods": ["get"],
"read_attributes": "(**)"
}
]
}
]
}
{
"name": "AdvancedAuth",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.globals.unset(\"accessToken\");",
"",
"pm.test(\"Access Token successfully retrieved\", function() {",
" pm.expect(pm.response.code).to.be.oneOf([200, 201, 202]);",
"})",
"",
"var jsonData = pm.response.json();",
"pm.collectionVariables.set(\"accessToken\", jsonData.access_token);"
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disabledSystemHeaders": {}
},
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "{{bm_password}}:{{pw}}",
"type": "string"
},
{
"key": "username",
"value": "{{bm_user}}",
"type": "string"
},
{
"key": "showPassword",
"value": false,
"type": "boolean"
}
]
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "Host",
"value": "{{client_url}}",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "grant_type",
"value": "urn:demandware:params:oauth:grant-type:client-id:dwsid:dwsecuretoken",
"type": "text"
}
]
},
"url": {
"raw": "https://{{client_url}}/dw/oauth2/access_token?client_id={{client_id}}",
"protocol": "https",
"host": [
"{{client_url}}"
],
"path": [
"dw",
"oauth2",
"access_token"
],
"query": [
{
"key": "client_id",
"value": "{{client_id}}"
}
]
}
},
"response": []
}
  1. Öffne das SLAS Admin UI deiner Organisation.

    SLAS Admin UI
  2. Lege einen neuen Client an und konfiguriere ihn wie folgt:

    FeldWert
    Client NameFrei wählbar, z. B. postman-dev
    Private Client?✅ aktiviert
    ScopesRelevante sfcc.shopper-* Scopes
    Redirect URIhttps://oauth.pstmn.io/v1/callback
    Channels/SitesSite ID(s) aus Schritt 1, z. B. B2C
    Login Restrict❌ deaktiviert
  3. Speichere den Client. Das Secret wird automatisch generiert.

  4. Notiere Client ID und Client Secret – du brauchst beides für Postman.

https://{SHORT_CODE}.api.commercecloud.salesforce.com/{API_FAMILY}/{API_NAME}/v1/organizations/{ORGANIZATION_ID}/
PlatzhalterWert
{SHORT_CODE}kv7kzm78
{API_FAMILY}product
{API_NAME}shopper-products
{ORGANIZATION_ID}f_ecom_zzte_053
{
"name": "Auth SCAPI",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.globals.unset(\"accessToken\");",
"",
"pm.test(\"Access Token successfully retrieved\", function() {",
" pm.expect(pm.response.code).to.be.oneOf([200, 201, 202]);",
"})",
"",
"var jsonData = pm.response.json();",
"pm.collectionVariables.set(\"accessToken\", jsonData.access_token);"
],
"type": "text/javascript",
"packages": {},
"requests": {}
}
},
{
"listen": "prerequest",
"script": {
"packages": {},
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "{{clientSecretSCAPI}}",
"type": "string"
},
{
"key": "username",
"value": "{{clientIdSCAPI}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "grant_type",
"value": "client_credentials",
"type": "text"
},
{
"key": "channel_id",
"value": "B2C",
"type": "text",
"uuid": "1c12a811-172f-4712-8683-a3b527a9564c"
}
]
},
"url": {
"raw": "https://{{shortCode}}.api.commercecloud.salesforce.com/shopper/auth/v1/organizations/{{organizationId}}/oauth2/token",
"protocol": "https",
"host": [
"{{shortCode}}",
"api",
"commercecloud",
"salesforce",
"com"
],
"path": [
"shopper",
"auth",
"v1",
"organizations",
"{{organizationId}}",
"oauth2",
"token"
]
}
},
"response": []
}