Skip to content
Advertisement

Change Woocommerce API functions to async/await using NodeJS in AWS Lambda

I am looking to change a couple of Woocommerce API calls so each function finishes before the next functions proceeds. However, I am unsure how to do this without breaking the specific Node Woocommerce API code.

https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#create-an-order-note

How can I change those two Woocommerce POST functions to Async/Await so it works with AWS Lambda?

(I have included an existing await function currently used in AWS Lambda as a reference)

JavaScript

Advertisement

Answer

There’s a method called postAsync for async calls in WooCommerce, you can try something like:

JavaScript

Every method can be used in a promified way just adding Async to the method name.

You can take a look to the docs here: https://github.com/woocommerce/wc-api-node#promified-methods


If it doesn’t work, you can always use it stacking calls like this:

JavaScript
Advertisement