JS / TS project

Javascript and Typescript project wrapper

View full module reference here
View available functions here
View models here under models
View an example project here

The Terra Javascript client is a powerful wrapper for backends relying on JS / TS libraries such as ExpressJS and others. It encapsulates:

  • Models for data parsing
  • Data requests for a specific user
  • Authentication requests
  • Users management

Adding the module

Install the package using NPM or Yarn

npm i terra-api
yarn i terra-api

Then add the package to your code

const { default: Terra } = require("terra-api");

Setup the module

Start off by setting up a managing Terra instance

const terra = new Terra("DEV_ID", "API_KEY");

This instance can now be used to execute the different actions for the specified dev-id


You can generate a widget session by specifying reference ID, providers, and optionally redirect URLs. This will return a TerraWidgetResponse promise, which contains status, session id, and URL.

    .then((s) => {
      // use the various response elements
        if(s.status == "success")

You can list available providers using the providers function

    .then((p) => {
    if(p.status == "success")

Manage Users

You can list your current subscribers or get the information of a particular user. The first returns a list of

terra.getUsers().then((r) => console.log(r.users));
terra.getUser("user_id").then((u) => console.log(u.user));

You can also deauthenticate a particular user


Data Getters

You can request data for a particular user, scope, and date range using the data getters. You can also specify if you'd like the response to your webhook or in the function promise

terra.getSleep("user_id", new Date(), undefined, false);