Loading

Best Practices for Headless, OCAPI & API solutions in B2C Commerce

Data pubblicazione: Dec 12, 2025
Descrizione

Common use cases of headless applications using OCAPI and recommended best practices to ensure platform’s performance and scalability.

Risoluzione

1. To expedite customer and order searches for data exports via API, ensure the Scripting API for Search is enabled for customers and orders in BM.

RecommendationReview the APIs for Customer Search content.

2. Don’t put lot of objects into a Pipeline Dictionary and iterate over them. Current Pipeline Dictionary Implementation stores objects using soft references in PDict stores while iterating over them can cause long living Pipeline Dictionaries to get lost.


Recommendation: Use the Script pipelet and query the objects with the B2C Commerce Script API and iterate over them within the same script. For more information, review The Scripting Pipelet.

3. If a bundle does not have its own inventory record and the Use Bundle Inventory Only option is not selected in the inventory list, the Available To Sell (ATS) value for a bundle should be calculated based on the availability of the bundled products. However, adding Product Bundle to the cart results in the Cannot read property “ATS” from null error.

Recommendation: This error happens in client-side code and hence can be fixed in custom code as outlined below:

var availableToSell = product.availabilityModel.inventoryRecord ? product.availabilityModel.inventoryRecord.ATS.value : 0;


4. Rewrite Custom job steps from steptypes.xml to steptypes.json. Going forward usage of steptypes.json will only be allowed for ease of use. For more information, see Steptypes.json Example.

5. Migrate your web service calls leveraging AXIS (webreference) to WebReference2 (CXFv3) as outlined in Apache Axis Retirement.

6. Only use hooks when necessary — as hooks introduce dependencies that can impact overall request performance.

7. Avoid requesting persisted objects from within a hook e.g. ProductMgr.getProduct() or product.getVariants().

8. Enable circuit breaker and set lower timeouts on the service to interoperate with 3rd party service provider endpoints within OCAPI hooks

9. For OCAPI OAuth optimization using their Account Manager subsystem, please see the following:

  • Use JWT token format instead of UUID for API Client ID token. This optimizes the response times and also the number of calls to the underlying identification subsystems like account manager.

  • All shop API requests does not require a new OAuth token and depending on use case, access tokens that are cached for 30 mins can be reused.

  • These best practices will help reduce 500 errors and 429 Too many requests errors. 


10. Avoid combined controllers and pipeline calls within a single OCAPI request for baskets. Instead, please use the BasketMgr.getCurrentBasket() script API from a controller request.

11. Avoid long running requests in custom hook logic attached to the OCAPI Shop GET resource.

Any custom hook logic should use performant and efficient code logic and should be load tested. Without proper load testing and efficient code to interoperate with 3rd party service provider endpoints within OCAPI hooks may result in frequent timeouts and piling up of requests that in turn may have cascading impact on site performance.
Enabling circuit breakers for tripping would provide some protection.

12. Avoid high response times on OCAPI Shop GET requests on products configured with promotions.

  • Reconfigure promotions by assigning qualifying products to a category instead of having individual list of product-ids assigned to a promotion.

  • Disable incremental indexing on products if it is enabled and replicate the search indexes from staging to production.

Numero articolo Knowledge

000389489

 
Caricamento
Salesforce Help | Article