Nodejs SDK

Info Contents
Version 2.0.0
License GNU Lesser General Public License Version 3

Instantiating the SDK

var KwsSdk = require('sa-kws-node-sdk');

// KWS will provide all the necessary info for your account
var kwsSdk = new KwsSdk({
    clientId: 'your_client_id',
    apiKey: 'your_api_key',
    kwsApiHost: '',

    // cross domain options
    /*(optional)*/ allowedDomains: [''], // array of allowed frontend domains
    /*(optional)*/ loginRedirectUrl: '',  // url to be redirected after the login
    /*(optional)*/ logoutRedirectUrl: '',  // url to be redirected after the logout
    /*(optional)*/ debug: true,  // by default equal false. will log the errors in the console using the logger options
    /*(optional)*/ logger: console.warn  // by default equal to console.log

Adding controller handlers for oauth callbacks

// assuming that app is your express instance object

Get Users Map

This call allows you to get the number of users aggregated by area (postal code related).

  • Function: app.user.getMap

  • Parameters:

    • countryCode: (string, required) ISO 3166-1 2 chars code
  • Response: It depends on the country. This could be an example for UK

    "n1": 200,
    "n12": 200,
    "n233": 200,
    "n244": 200,
    "n355": 200,
    "n366": 55,
  • Example:{countryCode:'GB'})
    .then(function (data) {
        // Your resp handler here
    .catch(function (err) {
        // Your error handler here

Get App Statistics

This function allows you to get the total points that have been awarded by the app.

  • Function: app.getStatistics

  • Parameters: none

  • Response:

    • totalPointsAwarded (Number)


    "totalPointsAwarded": 1054782
  • Example:
    .then(function (data) {
        // Your resp handler here
    .catch(function (err) {
        // Your error handler here


This function allows you to send a notification to one or more users of the app.

  • Function: app.notify

  • Parameters:

    • targetUserIds (Array of integers, required) ids of the target users
    • description (string, required) message to be sent (html accepted)
  • Response: Empty

  • Example:{
    targetUserIds: [125],
    description: 'Thank you!<br/><br/>Your welcome package has been sent!'
}).then(function () {
    // Your resp handler here
}).catch(function (err) {
    // Your error handler here

User functions

Requests coming from the frontend will have the possibility to make calls related to the user session. These kind of calls are preferably made from the frontend directly, but there might be some ocassions when doing it from the backend can be useful.

The following example is a middleware that injects the user profile data in the req object:

app.use(function (req, res, next) {

    // saUserSdk is now injected in the req obj and allows to make calls with the user session
        .then(function (userData) {
            req.user = userData;
        .catch(function () {
            // No user data could be fetched
            req.user = null;

The functions that are available from the userSdk object are the same as in the frontend SDK. Please see Frontend SDK reference for details.