Announcements
Why Use SCAPI
Base URL and Request Formation
Quick Start
Hook Method Details
Custom Properties
Remote Includes
SCAPI Specifications
B2C Commerce Release Notes
Ask the Community
Use Remote Includes wisely, especially in combination with caching. Too many cache misses from Remote Includes will negatively affect the system performance. Also, be aware that authentication and authorization are only performed for the main request, but not for the include requests.
Important
With B2C Commerce 25.1, extend API responses by including responses from other sources using Remote Includes.
Include a response from a SCAPI Custom API or System API, for example to provide additional product details.
Example 1: The hook dw.ocapi.shop.product.modifyGETResponse is used to customize the product response. A Custom API endpoint, remoteInclude, delivers a sample which is added to the product with the custom property c_remote.
1exports.remoteInclude = function() {
2 var info = {
3 id: "test-id"
4 };
5 dw.system.RESTResponseMgr.createSuccess(info).render();
6}1exports.modifyGETResponse = function(scriptProduct, doc) {
2 var include = dw.system.RESTResponseMgr.createScapiRemoteInclude('custom', 'my-api', 'v1', 'remoteInclude');
3 doc.c_remote = {
4 value: [ include ]
5 };
6}Example 2: The hook dw.ocapi.shop.product.modifyGETResponse is used to customize the product response. It is enhanced with promotion data which is added to the product with the custom property c_remote.
1exports.modifyGETResponse = function(scriptProduct, doc) {
2 var include = dw.system.RESTResponseMgr.createScapiRemoteInclude('pricing', 'shopper-promotions', 'v1', 'promotions', dw.web.URLParameter("siteId", "MySite"), dw.web.URLParameter("ids", "my-first-promotion,my-second-promotion"));
3 doc.c_remote = {
4 value: [ include ]
5 };
6}Add multiple remote includes in the array to create complex and powerful responses.
Note
RestResponseMgr method createScapiRemoteInclude() allows only SCAPI URLs.RestResponseMgr method createStorefrontControllerRemoteInclude() allows only Controller URLs.Cross-API requests (for example, including a Controller response within a Custom API or SCAPI hook) are not possible.
Important
For additional information and examples, see RemoteInclude and Passing Data Between Hooks.