React Native
Terra initialization
initTerra
function initTerra(
devID: string,
referenceId: string,
): Promise<SuccessMessage>devId: string ➡ The dev-id provided to you when signing up with Terra Developer Dashboard
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. (E.g.Connections.APPLE_HEALTH,Connections.SAMSUNG,Connections.HEALTH_CONNECT)token: string➡ A token used for authentication. Generate one here: https://docs.tryterra.co/reference/generate-authentication-token(Optional)
customPermissions: Set<CustomPermissions>➡ This is defaulted as an emptySet. If you want to make a more granular permissions request, you may send us a set ofCustomPermissionsstartIntent: 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 AndroidschedulerOn: 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 TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook. If false,DataMessageon the returnedPromisewill contain the data in thedatafield.
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 TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook. If false,DataMessageon the returnedPromisewill contain the data in thedatafield.
returns
Promise<DataMessage>
getBody
This function requires toWebhook to be passed in as a keyword argument, and not as a positional argument
function getBody(
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 TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook. If false,DataMessageon the returnedPromisewill contain the data in thedatafield.
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 TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook. If false,DataMessageon the returnedPromisewill contain the data in thedatafield.
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 TimestampendDate: DateorendDate: Long➡ The end of the request in either Date or Unix TimestamptoWebhook: Bool➡ Whether or not to send data to your webhook. If false,DataMessageon the returnedPromisewill contain the data in thedatafield.
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,DataMessageon the returnedPromisewill contain the data in thedatafield.
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_.APPLEto write data to Apple Health.payload: TerraActivityPayload: ATerraActivityPayloadobject 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>>`
Last updated
Was this helpful?