Connect a User
Allow users to link their wearable devices with their health & fitness devices and apps so they can receive data
Prerequisites
API Key:
Obtain your API Key from the Terra Dashboard
Set up a webhook where Terra will send event updates.
Enable the specific data sources your app requires (e.g., activity, sleep, body metrics).
Overview
Connecting a User is equivalent to creating a connection to one Provider account.
You can connect a user through Terra through 3 principal methods.
Through the Dashboard UI, for testing and demo purposes
Through Terra's pre-build authentication widget
Through building your own UI
User limits
Note that for testing & development, there is a user limit of 50 users on each environment.
If you reach the user limit, kindly deregister testing accounts you no longer need using the #auth-deauthenticateuser endpoint
SDK providers
To connect to SDK-based integrations:
you will need to use the appropriate SDK functions instead, outlined in the mobile SDK-specific guide
Connect your first user
For demonstration purposes, if this is your first time connecting a User, you may connect one using the Terra Dashboard UI as below. This will help you understand the connection flow for a User without making any API calls yourself.
This allows you to test out the flow that an end user will follow when connecting their own wearable device
Build your own authentication flow
NEVER use a Webview or iframe to authenticate a user
Using a webview pauses security risks due to the invisible URL bar, meaning that the user cannot know the domain onto which they are entering their username & password. Providers may completely block authentication leading to an error during the flow
Instead, opt to use an in-app browser to open the URL returned by the #auth-generatewidgetsession or the #auth-authenticateuser endpoint
Choose your implementation
Terra offers you the option of using the pre-built authentication Widget in order to authenticate, or the ability to create your custom UI for users to select which health & fitness data source to connect.
The Terra Widget provides a customizable UI with just a single API call, offering options to adjust colors, edit text, and specify the devices available for user connection.
Building your own UI gives you complete control over every pixel of the device connection screen, at the cost of additional development time
Use the widget session endpoint in your backend to generate an authentication link, and retrieve the url
from the response.
The response will take the following form:
Pass the URL retrieved to your client side, and open either
an in-app browser, if using a mobile app
a new tab, if using a web app
This will take the end user to a device selection screen
Once the end user selects a source to connect to, they will be taken to that source's login screen
The end user will then need to log in and agree to the permissions requested by Terra
The permissions list below can be customized through your Terra Dashboard
After finishing authentication, the end user will be redirected either to a default success/failure page, or to the one you passed into the widget session endpoint as auth_success_redirect_url
or auth_failure_redirect_url
, respectively.
This may be
a page on your web app with any query parameters of your choice (e.g. https://somreallycoolcompany.com?terra_auth_success=true)
A deep link into your mobile app (e.g. reallycoolapp://success)
The user_id
, reference_id
, and source connected will be appended to the final URL, i.e. https://widget.tryterra.co/session/demo/success?user_id=bc205b50-dabe-4680-9d35-38517b915dc1&resource=GOOGLE&reference_id=null
Upon finishing the last step in the guide above, in either of the two implementations, you will receive an authentication success event in your destination.
User authentication events
Upon Connecting a User, you will notice that you received an auth
event upon connection
This Event signifies a new User has been created, following them logging into the login/authentication link provided to them.
The user_id
provided in this response is crucial to the functioning of Terra. It will be sent in all #data-events and needs to be used whenever you Request Historical data
If the user declines required permissions, or cancels authentication halfway through, you will receive an appropriate Event
This notifies your system that a new fitness data account has been created. Store this connection in your database, using the "reference_id" field to reconcile them back to an End User in your system.
User reauthentication
Connecting the same account twice on the same dev_id will ALSO lead to the following event being sent.
Connecting an account a second time on the same dev_id
will delete the previous user
record for that account, and yield a new user_id
. You will receive both an auth success event as well as a reauthentication event, as detailed below
This is done not to create duplicate records for a single account for a given dev ID.
Last updated
Was this helpful?