Service callbacks for building requests and parsing responses
Key Takeaway
createRequest builds the request from your Service.call() arguments. parseResponse turns the reply into result.object. For an HTTP service, the framework does not call your own execute callback unless the callback object sets executeOverride: true.
B2C Commerce code calls an external web service through the service framework. When you create a service instance, you pass in an object that holds callback functions you write. The framework runs those callbacks during the call. The createRequest callback turns the arguments you give to Service.call() into the real request. The parseResponse callback turns the raw reply into the object your code gets back. Which other callbacks you must write depends on the service type.
How to call a service
- Configure the service in Business Manager. There you give the service an ID and pick its service type: HTTP, HTTP Form, FTP, SFTP, SOAP or Generic.
- Create a service instance with
dw.svc.LocalServiceRegistry.createService(). Pass two arguments: the service ID and the callback object, which holds your callback functions. - Run the instance by calling
Service.call()with any arguments the request needs. - Check the
dw.svc.Resultthat comes back.
A service instance is a single-use object, so create a new instance for each call.