Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Shopify function asynchronous

Shopify function asynchronous

TuanDangA
Shopify Partner
17 0 7

 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 

Replies 3 (3)

jdorsch
Tourist
9 2 5

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}"

tgg-mholland
Shopify Partner
2 0 0

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.

Nick_Wesselman
Shopify Staff
171 43 73

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