Skip to main content

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.

Shopify NPM search

We can see inside the detailed page that this SDK will allow access to the REST and GraphQL API and manage authentication.

Shopify NPM detail page

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:

WooCommerce Libraries

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.

WooCommerce dependency

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

Doc initialization

WooCommerce init in Spell

Some changes made:

  • I don't have to do the require myself: Meta API do it automatically for me.
  • I've replaced var by const because we should not use var anymore
  • I've named my client wcClient instead of WooCommerce
  • I've match the name of WooCommerce initialization woocommerce instead of WooCommerceAPI 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!

WooCommerce's methods doc

So I'll use these methods like this inside Meta API, using async / await:

WooCommerce's methods in Spell

I can now use the WooCommerce SDK like I want and connect it to others APIs.