Step-by-step development guide
This guide will cover what you need to know to get started on building your application on top of the Slyk API using our Node SDK. The use case followed here is wanting to build a product that leverages a community built with Slyk, meaning that the application will use Slyk's user management as well as its e-commerce and reward systems. While it is possible to have your product manage its own users, outside of Slyk, that will not be covered on this guide.
The first thing you'll need to do is create an API key on your Slyk dashboard. You can see how that is done on the first step of the quick start guide.
Keep in mind that building an application that uses the Slyk API requires a bit of backend development. This is because you'll want to keep your Slyk API key secure, and not include it on your frontend code. The part of your application that connects with the Slyk API should then be on the backend.
This guide uses Next.js as the framework to build the examples, because it allows creating API routes, which is where we'll write the integration with the Slyk API.
Demo Application
The code in this guide is also the base for the open source demo application. Its source is available here: https://github.com/slykio/slyk-demo
If you want to see it working right away, you can try ourLive Demo
. Balances and checkout are fake and are only meant be used for testing purposes only.
Create a new API Key
Go to your Slyk dashboard.
On the main menu, go to Credentials and click on the CREATE NEW API KEY button.
Using the Slyk Node SDK
Install the Slyk Node SDK package with:
Or with:
Then you'll need a way to configure the API key you created. We advise using environment variables for this. In Next.js you can do so with a .env
file, which would look like this:
The name you give this environment variable is up to you.
With this set up, you should be able to access it on your code. You'll then need to create an instance of the Slyk SDK, like this:
You're now ready to start using the Slyk API.
For more information on the Slyk Node SDK take a look at its documentation.
Serializing Slyk SDK models
The getServerSideProps
method in Next.js requires all returned values to be serializable, so it's necessary to serialize model instances returned by the Slyk SDK manually. This can be done with JSON.stringify
and JSON.parse
for example, like this:
Keep that in mind when getting data from the Slyk API using the Slyk SDK.
Last updated