@biostrap/api
v0.0.4
Published
Biostrap API Node SDK
Readme
NODEJS BIOSTRAP API
Requirements
NodeJS > 18.0
Installation
Using npm
npm i --save @biostrap/apiUsing yarn
yarn add @biostrap/apiUsage
OAuth2.0
Create your oauth application in app.biostrap.com. Use the credentials of your app for authorization.
- Example 1: Using
import
import BiostrapApi from '@biostrap/api'
const biostrapAuth = new BiostrapApi.Oauth2({
clientId: '', // your client id from the oauth app
clientSecret: '', // your client secret from the oauth app
redirectUri: '', // your redirect uri
authorizationEndpoint: '', // https://dev.auth.biostrap.com/authorize for test or https://auth.biostrap.com/authorize for prod
tokenEndpoint: '', // https://dev.auth.biostrap.com/token for dev or https://auth.biostrap.com/token for prod
scopes: []
})
// in login route
const biostrapAuthorizationUrl = biostrapAuth.getAuthorizationUrl()
// in the callback route
const tokenData = await biostrapAuth.getToken(code);
const { access_token, refresh_token, expires_in, token_type } = tokenData;
// Save the tokens to use biostrap services. Send them along with the other requests.
- Example 2: Using
require
const BiostrapApi = require('@biostrap/api')
const biostrapAuth = new BiostrapApi.Oauth2({
clientId: '', // your client id from the oauth app
clientSecret: '', // your client secret from the oauth app
redirectUri: '', // your redirect uri
authorizationEndpoint: '', // https://dev.auth.biostrap.com/authorize for test or https://auth.biostrap.com/authorize for prod
tokenEndpoint: '', // https://dev.auth.biostrap.com/token for dev or https://auth.biostrap.com/token for prod
scopes: []
})
// in login route
const biostrapAuthorizationUrl = biostrapAuth.getAuthorizationUrl()
// in the callback route
const tokenData = await biostrapAuth.getToken(code);
const { access_token, refresh_token, expires_in, token_type } = tokenData;
// Save the tokens to use biostrap services. Send them along with the other requests.
Api
Using the saved access_token to retrieve the data of a specific user.
const Biostrap = require('@biostrap/api')
const biostrapApi = new Biostrap.Api({
access_token: '',
refresh_token: '',
environment: 'test' | 'prod'
})Sleep
Use the above created API instance to fetch sleep details.
try {
const sleep = await biostrapApi.sleep.getDailySleep("2023-03-07");
} catch(err) {
// handle the error
}Available methods in Sleep
- getSleepStats('YYYY-MM-DD')
- getDailySleep('YYYY-MM-DD')
- getWeeklySleep('YYYY-MM-DD')
- getMonthlySleep('YYYY-MM-DD')
- getYearlySleep('YYYY-MM-DD')
Steps
Available methods in steps
- getDailySteps('YYYY-MM-DD')
- getWeeklySteps('YYYY-MM-DD')
- getMonthlySteps('YYYY-MM-DD')
- getYearlySteps('YYYY-MM-DD')
Scores
Available methods in scores
- getDailyScores('YYYY-MM-DD')
- getDailyRecoveryScores('YYYY-MM-DD')
- getWeeklyRecoveryScores('YYYY-MM-DD')
- getMonthlyRecoveryScores('YYYY-MM-DD')
- getYearlyRecoveryScores('YYYY-MM-DD')
Calorie
Available methods in calorie
- getDailyCalories('YYYY-MM-DD')
- getWeeklyCalories('YYYY-MM-DD')
- getMonthlyCalories('YYYY-MM-DD')
- getYearlyCalories('YYYY-MM-DD')
Biometrics
Available methods in biometrics
- getBiometrics(timestamp with millisecond , limit < 50)
Activities
Available methods in activities
- getActivities(timestamp with millisecond , limit < 50)
For more detailed documentation visit our documentation
