The sdk360 is an advanced JavaScript SDK
crafted for developers building health and wellness
applications, offering robust support for tracking and analyzing
user health metrics. It facilitates seamless integration with
devices, enabling monitoring of key parameters like sleep data,
calorie consumption, step counts, and quiz-based assessments.
With built-in features such as device connection validation,
user authentication via API credentials, and streamlined data
management, sdk360 ensures developers can quickly deploy
efficient, scalable solutions. Its lightweight design and
cross-platform compatibility make it ideal for modern web and
mobile environments.
The SDK’s extensibility and modular structure allow developers
to build applications that provide users with actionable
insights into their health and lifestyle. By leveraging this
toolkit, you can create personalized health solutions, enhancing
user engagement and promoting well-being.
For detailed installation steps and documentation, visit the
npm package page.
To install the SDK, use the following command:
npm install @droobismit/sdk360
To install all the peerdependencies, use the following command:
npm i pnpm
npx install-peerdeps @droobismit/sdk360
Code copied to clipboard!
Android Configuration
-
Set Minimum SDK Version
Update
minSdkVersion
in your
android/build.gradle
to 28 or above.
-
Add Permissions to
AndroidManifest.xml
Navigate to
android/app/src/main/AndroidManifest.xml
and add the following permissions:
<-- Essential Health Data Permissions -->
<uses-permission
android:name="android.permission.health.READ_STEPS" />
<uses-permission
android:name="android.permission.health.READ_SLEEP" />
<uses-permission
android:name="android.permission.health.READ_EXERCISE"
/>
<uses-permission
android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"
/>
<uses-permission
android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"
/>
<-- Make it remove so this permission is not required
-->
<uses-permission
android:name="android.permission.health.READ_HEART_RATE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_BASAL_METABOLIC_RATE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_BLOOD_GLUCOSE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_BLOOD_PRESSURE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_BODY_FAT"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_BODY_TEMPERATURE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_BODY_WATER_MASS"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_BONE_MASS"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_DISTANCE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_ELEVATION_GAINED"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_FLOORS_CLIMBED"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_HEART_RATE_VARIABILITY"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_HEIGHT"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_HYDRATION"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_LEAN_BODY_MASS"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_MENSTRUATION"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_NUTRITION"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_OXYGEN_SATURATION"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_POWER"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_RESPIRATORY_RATE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_RESTING_HEART_RATE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_SPEED"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_STEPS_CADENCE"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_SWIMMING_STROKES"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_VO2_MAX"
tools:node="remove" />
<uses-permission
android:name="android.permission.health.READ_WEIGHT"
tools:node="remove" />
-
Add Privacy Policy Intent Filters
Include these under the
MainActivity
in
AndroidManifest.xml
:
In
AndroidManifest.xml
include the following under the Activity you wish to
display to the user when user wants to see your app's
privacy policy:
Add them to the MainActivity
activity so both will run when the user launches your app
<intent-filter>
<action
android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE"
/>
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.VIEW_PERMISSION_USAGE"
/>
<category
android:name="android.intent.category.HEALTH_PERMISSIONS"
/>
</intent-filter>
-
Update Proguard Rules
-keep class co.tryterra.** { *; }
iOS Configuration
-
Set Minimum Deployment
Update
Minimum Deployment Target
for your app to iOS 13.0+.
-
Enable HealthKit
-
Add HealthKit as a capability to your
project.
-
Enable Background Delivery in the
HealthKit entitlements.
<dict>
<key>com.apple.developer.healthkit</key>
<true />
<key>com.apple.developer.healthkit.background-delivery</key>
<true />
</dict>
-
Add Privacy Keys
Go to Info.plist and include the following:
-
Go to main app folder > Click on the icon below TARGETS on
the sidebar > click on Info on menu bar > go to Custom iOS
Target Properties > hover over any key and click + button
> add Privacy - Health Share Usage Description, once you
add , you info.plist wil have these , you can change the
string as per your requirement which will be visible for
user
<key>NSHealthShareUsageDescription</key>
<string>We require
access to your health data to provide personalized
insights.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We need to
update your health data to ensure accuracy.</string>
-
Enable Background Modes
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
</array>
-
Add Background Task Scheduler
Add the following to
Info.plist
:
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>co.tryterra.data.post.request</string>
</array>
-
Setup Background Delivery
Add this code to your AppDelegate’s
didFinishLaunchingWithOptions
function:
[Terra setUpBackgroundDelivery];
SDK Initialization
Initialize the SDK for both Production and Testing environments.
Required Parameters
Parameter |
Type |
Description |
Default |
userId |
string
|
User's unique ID. |
Required |
apiKey |
string
|
API key. |
Required |
apiSecret |
string
|
API secret. |
Required |
language |
string
|
Language for the SDK (en
or ar ).
|
en |
fullName |
string
|
User's full name. |
Optional |
autoUpdateIntervalInMinutes
|
number
|
Interval (in minutes) to refresh APIs. |
Optional |
handleInfoPoints |
function
|
Function to handle Info Points click. |
Optional |
handleRedeemPoints |
function
|
Function to handle Redeem Points click. |
Optional |
Production Environment Initialization
Use the
init360
function
to initialize the SDK in the Production environment.
import { init360 } from '@droobismit/sdk360';
// Configuration for Production
const prodConfig = {
userId: 'yourUserId',
apiKey: 'yourApiKey',
apiSecret: 'yourApiSecret',
language: 'en', // or 'ar'
fullName: 'userFullName', // Optional
autoUpdateIntervalInMinutes:5, // Optional
handleInfoPoints:handleInfoPoints, // Optional
handleRedeemPoints:handleRedeemPoints // Optional
};
// For production version, use init360
init360(prodConfig)
.then(() => console.log('SDK initialized successfully in Production'))
.catch(error => console.error('SDK initialization failed in Production:', error));
Testing Environment Initialization
Use the
init360QA
function to initialize the SDK in the Production environment.
import { init360QA } from '@droobismit/sdk360';
// Configuration for Testing (QA)
const testConfig = {
userId: 'testUserId',
apiKey: 'testApiKey',
apiSecret: 'testApiSecret',
language: 'en', // or 'ar'
fullName: 'testUserFullName', // Optional
autoUpdateIntervalInMinutes: 5, // Optional
handleInfoPoints: handleInfoPoints, // Optional
handleRedeemPoints: handleRedeemPoints // Optional
};
init360QA(testConfig)
.then(() => console.log('SDK initialized successfully in QA mode'))
.catch(error => console.error('SDK initialization failed in QA mode:', error));
Device Connectivity
Check Device Connection
Verify if a device is connected for the user:
import { checkDeviceConnection } from '@droobismit/sdk360';
checkDeviceConnection()
.then(isConnected=> {
if (isConnected) {
console.log('Device is connected.');
} else {
console.log('No device connected.');
}
})
.catch(error => {
console.error('Error checking device connection:', error);
});
Get Detailed Device Status
Retrieve detailed status of connected devices:
import { getDetailedDeviceStatus } from '@droobismit/sdk360';
getDetailedDeviceStatus()
.then(response => {
console.log('response ',response );
})
.catch(error => {
console.error('Error checking device details :', error);
});
Device List Screen
Use the
DevicesList
component to display the device list component to connect
devices:
import { DevicesList } from '@droobismit/sdk360';
const App = () => {
return <DevicesList/>;
};
Health Content Library
Use the
HealthContentLibrary
component to display the content library screen:
import { HealthContentLibrary } from '@droobismit/sdk360';
const App = () => {
return <HealthContentLibrary/>;
};
Health Graph
Use the
HealthGraphView
component to display the content library screen:
import { HealthGraphView } from '@droobismit/sdk360';
const App = () => {
return <HealthGraphView/>;
};
Quiz Screen
A React Native quiz module that displays daily health questions,
handles user responses, shows correct/incorrect feedback with
explanations, and rewards points for correct answers through a
congratulatory popup.
Required Parameters
successPopupSubmitCallback :Optional callback that runs
after user collects points from popup.
import { HealthThreeSixtyQuiz } from '@droobismit/sdk360';
const App = () => {
return <HealthThreeSixtyQuiz/>;
};
Success Popup
A modal component that shows a congratulatory message with
earned points and a collect button. Displays points in a
stylized view with background image.
Required Parameters
-
showPopup
:
Controls modal visibility (boolean)
-
handleClose
:
Called when modal is closed (function)
-
handleSubmit
:
Called when "Collect Points" is pressed (function)
-
points
: Points
to display in popup (number, default: 10)
import { Popup } from '@droobismit/sdk360';
const App = () => {
return <Popup/>;
};
Points Management
The SDK provides several methods to manage and retrieve user
scores and rankings.
Get User Points Details
Retrieve detailed score information for a specific activity
type:
import { fetchUserPoints } from '@droobismit/sdk360';
try {
const scoreDetails = await fetchUserPoints({
fromDate: '2024-03-01',
toDate: '2024-03-14',
type: 'STEP', // Available types: 'STEP', 'SLEEP', 'CALORIES', 'QUIZ'
page: 1, // Optional, defaults to 1
size: 10 // Optional, defaults to 10
});
} catch (error) {
console.error('Error:', error);
}
Get Leaderboard
Retrieve user rankings for a specified period:
import { fetchLeaderboard } from '@droobismit/sdk360';
try {
const leaderboard = await fetchLeaderboard({
fromDate: '2024-03-01',
toDate: '2024-03-14',
page: 1, // Optional, defaults to 1
size: 10 // Optional, defaults to 10
});
} catch (error) {
console.error('Error:', error);
}
Get Points Summary
Retrieve a summary of user points for a specified period:
import { fetchPointsSummary } from '@droobismit/sdk360';
try {
const leaderboard = await fetchPointsSummary({
fromDate: '2024-03-01',
toDate: '2024-03-14',
});
} catch (error) {
console.error('Error:', error);
}
Get Reward Rules
Retrieve the current reward rules and conditions:
import { fetchRewardsRules } from '@droobismit/sdk360';
try {
const rules = await fetchRewardsRules({
fromDate: '2024-03-01',
toDate: '2024-03-14',
});
} catch (error) {
console.error('Error:', error);
}
Parameter Validation
The SDK performs strict validation on all parameters:
- Dates: Must be in 'YYYY-MM-DD' format
-
Activity Types: Must be one of: 'STEP',
'SLEEP', 'CALORIES', 'QUIZ'
If any validation fails, the SDK throws a
HealthThreeSixtyError
with appropriate error code and message.
Health Statistics
Today's Health Data
Get today's health statistics:
import {
fetchTodaysSteps,
fetchTodaysCalories,
fetchTodaysSleep
} from '@droobismit/sdk360';
// Get today's step count
const stepsData = await fetchTodaysSteps();
// Returns: { date: "2024-03-14", value: 8547 }
// Get today's calories burned
const caloriesData = await fetchTodaysCalories();
// Returns: { date: "2024-03-14", value: 1850 }
// Get today's sleep duration
const sleepData = await fetchTodaysSleep();
// Returns: {
// date: "2024-03-14",
// value: 27000, // seconds
// formatted: "07:30" // HH:MM format
// }
Historical Health Records
Get health data for a specific date range:
import {
fetchStepsRecords,
fetchCaloriesRecords,
fetchSleepRecords
} from '@droobismit/sdk360';
// Get steps data for a date range
const stepsData = await fetchStepsRecords("2024-03-01", "2024-03-07");
// Returns: [
// { date: "2024-03-01", value: 9876 },
// { date: "2024-03-02", value: 10234 },
// ...
// ]
// Get calories data for a date range
const caloriesData = await fetchCaloriesRecords("2024-03-01", "2024-03-07");
// Returns: [
// { date: "2024-03-01", value: 1950 },
// { date: "2024-03-02", value: 2100 },
// ...
// ]
// Get sleep data for a date range
const sleepData = await fetchSleepRecords("2024-03-01", "2024-03-07");
// Returns: [
// {
// date: "2024-03-01",
// value: 27000, // seconds
// formatted: "07:30" // HH:MM format
// },
// ...
// ]
Parameter Validation
For historical records methods:
-
startDate: Must be in 'YYYY-MM-DD' format
-
endDate: Must be in 'YYYY-MM-DD' format
Sync Health Data
Manually sync health data from SDK providers (Apple Health,
Google Fit, etc.):
import {
syncHealthData
} from '@droobismit/sdk360';
// Sync with default dates (today)
const syncResults = await syncHealthData();
// Or sync with specific date range (DD-MM-YYYY format)
const syncResults = await syncHealthData({
startDate: '01-12-2024',
endDate: '31-12-2024'
});
// Returns: {
// provider: "APPLE", // or other SDK provider
// type: "SDK",
// syncTime: "2024-03-14T10:30:00.000Z",
// dateRange: {
// startDate: "2024-12-01T00:00:00.000Z",
// endDate: "2024-12-31T23:59:59.999Z"
// },
// status:"success"
// }
Parameter Validation
-
startDate (optional): Start date in
DD-MM-YYYY format. Defaults to start of current day
-
endDate (optional): End date in DD-MM-YYYY
format. Defaults to current time
Error Handling
try {
const stepsData = await fetchTodaysSteps();
} catch (error) {
switch (error.code) {
case 7400: // DATA_ERROR
console.error('Failed to fetch health data');
break;
case 7501: // MISSING_PARAMETER
console.error('Missing required parameters');
break;
case 7603: // USER_NOT_INITIALIZED
console.error('User not initialized');
break;
case 7701: // NO_DEVICE_CONNECTED
console.error('No connected devices found');
break;
case 7702: // INVALID_PROVIDER
console.error('Provider not supported for manual sync');
break;
case 7703: // SYNC_FAILED
console.error('Health data synchronization failed');
break;
default:
console.error('An unexpected error occurred:', error.message);
}
}
Notes
-
All methods require the SDK to be initialized with
init360()
or
init360QA()
first
-
Manual Health Sync works with SDK providers (Apple Health,
Google Fit, Health Connect, Samsung Health)
-
API providers (Garmin, Fitbit, etc.) are not supported for
manual sync
-
Sleep duration is provided in both seconds (
value
) and
formatted HH:MM string
formatted
-
Delete node_modules inside sdk360 if error comes from
react-native(to automate add to the scripts in package.json -
"postinstall": "rd /s /q node_modules" (windows OS) ,
"postinstall": "rm -rf node_modules/sdk360/node_modules" (Mac
OS)
Request Headers
- accept-language: en/ar
- x-api-key: *********************
- x-api-secret: *********************
- Content-Type: application/json
Get Leaderboard Summary
API provides a concise overview of leaderboard rankings, scores,
and participant statistics for tracking performance.
GET
api/v1/external/user/{id}/score/summary
Request Payload
- id: User Id
-
from(Optional): Must be in 'YYYY-MM-DD'
format
-
to(Optional): Must be in 'YYYY-MM-DD' format
Success Payload
{
"sleep": 0,
"step": 0,
"quiz": 0,
"calories": 0,
"redeemed": 0,
"total": 0
}
Get Leaderboard Rank
API retrieves the current ranking and performance details of a
specific user within the leaderboard.
GET
api/v1/external/user/score/rank
Request Payload
- id: User Id
- page: Must be a number, defaults to 1
- size: Must be a number, defaults to 10
-
from(Optional): Must be in 'YYYY-MM-DD'
format
-
to(Optional): Must be in 'YYYY-MM-DD' format
Success Payload
{
"content": [
{
"fullName": "string",
"userId": "23432480-72373-0238-3028",
"rank": 10,
"totalScore": 1000
}
],
"page": 1,
"size": 10,
"totalElements": 1,
"totalPages": 0,
"last": true
}
Get Leaderboard Detail
API retrieves the current ranking and performance details of a
specific user within the leaderboard.
GET
api/v1/external/user/{id}/score/detail
Request Payload
- id: User Id
- page: Must be a number, defaults to 1
- size: Must be a number, defaults to 10
-
type(Optional): Must be one of: 'STEP',
'SLEEP', 'CALORIES', 'QUIZ'
-
from(Optional): Must be in 'YYYY-MM-DD'
format
-
to(Optional): Must be in 'YYYY-MM-DD' format
Success Payload
{
"content": [
{
"id": "831203-8319803-92310-93102",
"type": "STEP",
"date": "2024-12-16",
"score": 0,
"userId": "831203-8319803-92310-93102",
"createdAt": "2024-12-16T21:15:50.336Z",
"updatedAt": "2024-12-16T21:15:50.336Z"
}
],
"page": 1,
"size": 10,
"totalElements": 1,
"totalPages": 0,
"last": true
}
Get Sleep Data
API retrieves comprehensive sleep metrics, including duration,
quality, and patterns, to provide insights into user sleep
behavior over a specified period.
GET
api/sleep/external/user/{id}/summary
Request Payload
- id: User Id
- from: Must be in 'YYYY-MM-DD' format
- to: Must be in 'YYYY-MM-DD' format
Success Payload
{
"date": "2024-12-17",
"sleep": {
"totalDurationAsleep": 0,
"totalDurationLightSleep": 0,
"totalDurationDeepSleep": 0,
"totalDurationRemSleep": 0
}
}
Get Steps Data
API retrieves step count details for a specified period,
providing insights into a user’s daily activity and physical
movement patterns.
GET
api/activity/external/user/{id}/step
Request Payload
- id: User Id
- from: Must be in 'YYYY-MM-DD' format
- to: Must be in 'YYYY-MM-DD' format
Success Payload
[
{
"date": "string",
"value": 0
}
]
Get Calories Data
API retrieves information on calories burned, including active
and total calorie metrics, over a specified period, providing
insights into a user’s energy expenditure.
GET
api/activity/external/user/{id}/calories
Request Payload
- id: User Id
- from: Must be in 'YYYY-MM-DD' format
- to: Must be in 'YYYY-MM-DD' format
Success Payload
[
{
"date": "string",
"value": 0
}
]
Get Reward Points Rules
API retrieves the rules and criteria for earning reward points,
providing clarity on how users can accumulate points based on
their activities and achievements.
GET
api/v1/external/score-rules
Success Payload
[
{
"id": "xxxxxxx-xxxx-xxx-xxx-xxxx",
"scoreType": "STEP",
"value": 0,
"point": 0,
"condition": "LESS_THAN_OR_EQUAL" / "GREATER_THAN_OR_EQUAL" / "EQUAL",
"clientId": "xxxxx-xxx-xxx-xxx-xxxxxx",
"status": 0,
"createdAt": "2024-12-17T03:12:55.265Z",
"updatedAt": "2024-12-17T03:12:55.265Z"
}
]
Update Reward Points Rules
API allows modification of the existing criteria and rules for
earning reward points, enabling customization to align with
updated goals and user engagement strategies.
PUT
api/v1/external/score-rules/{id}
Request Payload
- id: Rule Id
-
body: { "scoreType": "STEP" / "SLEEP" /
"QUIZ" / "CALORIES" , "value": 0, "point": 0, "condition":
"GREATER_THAN_OR_EQUAL" }
Redeem Points
API facilitates the process of redeeming accumulated reward
points for specified benefits, ensuring a smooth and transparent
transaction for users.
POST
api/v1/external/user/{id}/score/redeem
Request Payload
- id: User Id
- body: { "score": xxx }