Using SDK with unsupported API
Using a NodeJS SDK to connect to an API
Some APIs don't have a public OpenAPI specification file or their API can be difficult to reimplement in OpenAPI.
One solution is to use their NodeJS or JavaScript SDK inside your Spell.
This usage come with some limitations:
- You won't be able to see the connectors performances and error rate inside your logs
- You'll have to manage manually errors if you want detailed information
But your Spell will still have global monitoring and you can mix NodeJS SDK with our connectors code.
Where can I find a NodeJS SDK
First, you can check on NPM to see if an SDK exist. We recommend you to only use official SDK for the best support.
We can see inside the detailed page that this SDK will allow access to the REST and GraphQL API and manage authentication.
You can also see references for official package inside the vendor's developer page. Look for SDK
, Libraries
or NodeJS client
.
Here is an example with WooCommerce:
Example with WooCommerce
Once we have the official NodeJS SDK, we will add it as a dependency inside our Spell. You can consult this guide if you need more information.
I've changed the default alias for a simple use inside my Spell.
Now I'm following the WooCommerce SDK's documentation to know how to use it. The first thing to do is to initialize the WooCommerce client.
I copy and paste the code from the doc and make some edit to match my configuration
Some changes made:
- I don't have to do the
require
myself: Meta API do it automatically for me. - I've replaced
var
byconst
because we should not use var anymore - I've named my client
wcClient
instead ofWooCommerce
- I've match the name of WooCommerce initialization
woocommerce
instead ofWooCommerceAPI
to match the alias
Of course, I'll also have to configure the url
and my consumer key
and secret
in order to use it.
Next, I can see inside the documentation that this SDK will expose "promified" method to consume this API. That's perfect!
So I'll use these methods like this inside Meta API, using async / await
:
I can now use the WooCommerce SDK like I want and connect it to others APIs.