Consuming an API from a Salesforce Commerce Cloud controller

624 views Asked by At

Inside a SFCC custom controller, at a certain point I need to consume an API and wait for its response before continuing. In fact, the my controller's response depends on the API's response itself.

Unless I'm mistaken, the SFCC documentation doesn't provide any code sample about that.

Express apparently provides a solution (see the very beginning of https://zellwk.com/blog/async-await-express/ for example), but SFCC middleware doesn't seem to handle the async keyword when defining a request handler.

Can anybody help on this one?

Thanks

1

There are 1 answers

0
Hayreddin Tüzel On

There is no way to handle async code on SFCC natively. And you need to change your code's structure according to this restriction. But you can use some jobs as a workaround.

Please check this link for more information about this concept: https://medium.com/@osapishchuk/asynchronous-execution-within-sfcc-9cc6226e1ac6