Table of Contents
Create a Nettu app
To get started using the SDK make sure you have a workspace in Nettu, or create one here
Getting a token to use the API
In order to authenticate your app you will have to pass an API-KEY with your requests. You can find this key in your company settings in the web portal.
Set up your local project
If you don’t already have a project, let’s create a new one. In an empty directory, you can initialize a new project using the following command:
npm init -y
Install the @nettu/sdk-js
package and save it to your package.json dependencies using the following command:
# Using NPM:npm i @nettu/sdk-js
Create a new file called tutorial.js
in this directory and add the following code:
tutorial.js
const { NettuClient } = require('@nettu/sdk-js');console.log('Getting started with Javascript Nettu SDK');
Back at the command line, run the program using the following command:
node tutorial.js
If you see the same output as above, we’re ready to start.
Get sales
It is common to report on your sales number from other websites. This is how you retrieve your sales stats from Nettu with the SDK.
tutorial.js
const { NettuClient } = require('@nettu/sdk-js');// Create a new instance of the NettuClient class with the api_key / token read from your environment variableconst client = NettuClient.create(process.env.NETTU_API_KEY);(async () => {try {// Use the `users.create` method to create a user associated with your Nettu appconst { count, total, sales } = await client.company.sales();console.log("Number of sales in period: "+count);console.log("Total sales in period: "+total);console.log("Your most recent sales");sales.map(console.log)} catch (error) {console.log(error);}})();
Next steps
You just built your first Nettu app with Javascript! 🎉💃🌮
There’s plenty more to learn and explore about this SDK and the Nettu platform. Here are some ideas about where to look next:
- More examples: We keep a list of common use cases with code examples in our Github repo so that you can get started fast. Check them out here
- This tutorial only used two of over 130 Web API methods available. Look through them to get ideas about what to build next!
- Tokens are an important part of using the Slack platform. New apps are recommended to start with a Bot User, which allows the app to use a bot token. Learn about the different types of tokens.
- You now know how to build a Slack app for a single workspace, learn how to implement Slack” OAuth to make your app installable in many workspaces. If you are using Passport to handle authentication, you may find the @aoberoi/passport-slack strategy package helpful.