Terra Docs
Dashboard
  • Docs
  • API Reference
  • Changelog
  • Health & Fitness API
    • REST API Endpoints
    • Supported integrations
    • Event Types
    • Data models
    • Samples
    • Core concepts
    • Destinations
    • Mobile SDK
      • iOS (Swift)
      • Android (Kotlin)
      • React Native
      • Flutter
  • Streaming API
    • REST API Endpoints
    • Supported Integrations
    • Core Concepts
    • Websocket Reference
    • Mobile SDK
      • iOS (Swift)
      • Android (Kotlin)
      • Flutter
      • React Native
  • Teams API - Beta
    • Supported Integrations
    • Core Concepts
    • API Endpoints
    • Event types
Powered by GitBook
On this page
  • Terra initialization
  • initTerra
  • Connection setup/magement
  • initConnection
  • getUserId
  • Data retrieval
  • DataMessage
  • getActivity
  • getDaily
  • getSleep
  • getNutrition
  • getAthlete
  • Writing data
  • postActivity
  • Android-only methods
  • grantedPermissions

Was this helpful?

  1. Health & Fitness API
  2. Mobile SDK

React Native

PreviousAndroid (Kotlin)NextFlutter

Last updated 2 months ago

Was this helpful?

Terra initialization

initTerra

function initTerra(
  devID: string,
  referenceId: string,
): Promise<SuccessMessage>

devId: string ➡ The dev-id provided to you when signing up with Terra referenceId: string ➡ A random string used to characterise a user on your server

returns Promise<SuccessMessage>

Connection setup/magement

initConnection

function initConnection(
  connection: Connections,
  token: string,
  schedulerOn: boolean,
  customPermissions: CustomPermissions[] = [],
  startIntent: String | null = null
): Promise<SuccessMessage>

Initialise a device connection. This function needs to be called once only when first creating the connection.

  • connection: Connections ➡ An ENUM from the Connections class signifying the connection you wish to initiate for.

  • (Optional) customPermissions: Set<CustomPermissions> ➡ This is defaulted as an empty Set. If you want to make a more granular permissions request, you may send us a set of CustomPermissions

  • startIntent: String? ➡ The path to the activity you wish to display when the user scans a freestylelibre from the background (i.e "co.tryterra.terra.example.MainActivity") Only valid for Android

  • schedulerOn: Bool ➡ A boolean dictating if you wish turn on background delivery. Defaults to true. Please see Background Delivery section for setup.

returns

  • Promise<SuccessMessage>

getUserId

function getUserId(connection: Connections): Promise<GetUserId>
  • connection: Connections ➡ An ENUM from the Connections class signifying the connection get user_id for.

returns

  • Promise<GetUserId>

Data retrieval

DataMessage

type DataMessage = {
  success: Boolean;
  data: Object;
  error: String | null;
};

getActivity

function getActivity(
  connection: Connections,
  startDate: Date,
  endDate: Date,
  toWebhook: Boolean = true
): Promise<DataMessage>
  • connection: Connections ➡ An ENUM from the Connections class signifying the connection you wish to initiate for.

  • startDate: Date ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: Bool ➡ Whether or not to send data to your webhook. If false, DataMessage on the returned Promise will contain the data in the data field.

returns

  • Promise<DataMessage>

getDaily

function getDaily(
  connection: Connections,
  startDate: Date,
  endDate: Date,
  toWebhook: Boolean = true
): Promise<DataMessage>
  • connection: Connections ➡ An ENUM from the Connections class signifying the connection you wish to initiate for.

  • startDate: Date ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: Bool ➡ Whether or not to send data to your webhook. If false, DataMessage on the returned Promise will contain the data in the data field.

returns

  • Promise<DataMessage>

getSleep

function getSleep(
  connection: Connections,
  startDate: Date,
  endDate: Date,
  toWebhook: Boolean = true
): Promise<DataMessage>
  • connection: Connections ➡ An ENUM from the Connections class signifying the connection you wish to initiate for.

  • startDate: Date ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: Bool ➡ Whether or not to send data to your webhook. If false, DataMessage on the returned Promise will contain the data in the data field.

returns

  • Promise<DataMessage>

getNutrition

function getNutrition(
  connection: Connections,
  startDate: Date,
  endDate: Date,
  toWebhook: Boolean = true
): Promise<DataMessage>
  • connection: Connections ➡ An ENUM from the Connections class signifying the connection you wish to initiate for.

  • startDate: Date ➡ The beginning of the request in either Date or Unix Timestamp

  • endDate: Date or endDate: Long ➡ The end of the request in either Date or Unix Timestamp

  • toWebhook: Bool ➡ Whether or not to send data to your webhook. If false, DataMessage on the returned Promise will contain the data in the data field.

returns

  • Promise<DataMessage>

getAthlete

function getAthlete(
  connection: Connections,
  toWebhook: Boolean = true
): Promise<DataMessage>
  • connection: Connections ➡ An ENUM from the Connections class signifying the connection you wish to initiate for.

  • toWebhook: Bool ➡ Whether or not to send data to your webhook. If false, DataMessage on the returned Promise will contain the data in the data field.

returns

  • Promise<DataMessage>

Writing data

postActivity

Writes activity data into Apple Health

/*
@Only available on iOS
*/
function postActivity(
  connection: Connections,
  payload: TerraActivityPayload
): Promise<SuccessMessage>
  • connection: Connections: The connection type (Connections_) for which to post the data. For example, Connections_.APPLE to write data to Apple Health.

  • payload: TerraActivityPayload: A TerraActivityPayload object that contains the activity data you wish to post. This can include details like activity type, heart rate, distance, calories, and other metrics.

returns

A Promise that resolves to a SuccessMessage object indicating the success of the operation or rejects with an error.

Android-only methods

Fetches permissions granted by Health connect

grantedPermissions

function grantedPermissions(): Promise<Array<String>>



**returns**

  • `Promise<Array<String>>`



token: string ➡ A token used for authentication. Generate one here:

Developer Dashboard
https://docs.tryterra.co/reference/generate-authentication-token