Discussing Shopify Functions development, deployment, and usage in Shopify apps.
Hi everyone, I'm developing a Shopify app extension (product-discount) that can edit cart item price based on prices provided by an API, the trouble now is I could not make the code to run asynchronously (to await for the API to get the price). Can someone help? anything will
This is entirely dependent on what language you are using. For instance, C# uses async/await, node.js uses promises, etc. You will likely get the best response by asking in a language specific format or googling "asynchronous rest request {languageIAmUsing}"
I'm having this same issue in a node typescript implementation. Returning a Promise<FunctionRunResult> causes the discount to not apply and no log output.
Functions do not support external API calls and the event loop is not enabled in our JavaScript engine, so promises/async generally will not work. See the documentation links below. Do you have a non-fetch use case that requires async?
https://shopify.dev/docs/apps/functions#limitations-and-considerations
https://shopify.dev/docs/apps/functions/language-support/javascript#available-javascript-apis
Nick Wesselman | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog