sfcc-ocapi-hooks

Build and validate OCAPI hooks for SFCC shop, data, and content APIs.

27|9|Updated Aug 8, 2025
One-click install
npx skills add https://github.com/taurgis/sfcc-dev-mcp --skill sfcc-ocapi-hooks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sfcc-ocapi-hooks
Source: https://github.com/taurgis/sfcc-dev-mcp/tree/main/ai-instructions/skills/sfcc-ocapi-hooks
Command: npx skills add https://github.com/taurgis/sfcc-dev-mcp --skill sfcc-ocapi-hooks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

OCAPI hooks provide server-side extension points that let you inject custom logic into the lifecycle of OCAPI requests, enabling augmentation, validation, or modification of API behavior without altering core platform code.

Core Features & Use Cases

  • Hook types: before<HTTP_Method>, after<HTTP_Method>, and modify<HTTP_Method>Response to customize request handling and responses.
  • Registration & structure: guidance for registering hooks in a cartridge via package.json and hooks.json, with recommended folder layouts and organization.
  • Real-world scenarios: validate incoming requests, enrich responses with custom attributes, and trigger external integrations while maintaining transactional integrity when needed.

Quick Start

Install and register a sample OCAPI hook workflow by adding scripts under cartridge/scripts/hooks and updating hooks.json accordingly.

Frequently Asked Questions about sfcc-ocapi-hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create and register OCAPI hooks in SFCC?

To create and register OCAPI hooks in SFCC, place CommonJS scripts under cartridge/scripts/hooks and update hooks.json and package.json accordingly. This structure supports before, after, and modifyResponse hooks across shop, data, and content APIs.

What are OCAPI hooks used for in Salesforce Commerce Cloud?

OCAPI hooks in Salesforce Commerce Cloud are server-side extension points that let you inject custom logic into API request lifecycles. They enable you to validate incoming requests, enrich responses with custom attributes, and trigger external integrations without altering core platform code.

Can I use OCAPI hooks to validate incoming SFCC API requests?

Yes, you can use OCAPI hooks to validate incoming SFCC API requests. By implementing before hooks, you can intercept and validate request payloads before they reach the core endpoint, ensuring adherence to security and reliability guidelines.

What is the difference between before, after, and modifyResponse hooks in SFCC OCAPI?

Before hooks intercept requests prior to core processing for validation, after hooks execute following core processing, and modifyResponse hooks alter the API response payload to enrich data with custom attributes.

Do I need to follow CommonJS structure for SFCC OCAPI hooks?

Yes, SFCC OCAPI hooks must follow the CommonJS script structure. Adhering to this standard is required for proper hook registration and satisfies the platform's security, performance, and reliability guidelines.

How do OCAPI hooks maintain transactional integrity during external integrations?

OCAPI hooks maintain transactional integrity during external integrations by applying specific performance and reliability guidelines. You can trigger external calls within after or modifyResponse hooks while preserving transactional state.