React Native
Streaming to Terra's Server
import { getUserId, startRealtime, Connections, DataTypes } from 'terra-rt';
const startServerStreaming = async () => {
// 1. Get the Terra user ID
const { userId } = await getUserId();
if (!userId) return;
// 2. Get a streaming token from your backend
const tokenResponse = await fetch('YOUR_BACKEND_URL/streaming-token', {
method: 'POST',
body: JSON.stringify({ userId }),
});
const { token } = await tokenResponse.json();
// 3. Start streaming with the token — data goes to BOTH your app and Terra's server
const dataTypes = [DataTypes.HEART_RATE, DataTypes.STEPS];
await startRealtime(Connections.BLE, dataTypes, token);
};Generates a single-use token for a user (producer) connection. The id
identifies the user the token is scoped to — a v6 connection id or a v5
compatibility user UUID — and must belong to the authenticating
developer.
Authorizations
x-api-keystringRequired
Your API key for authentication
dev-idstringRequired
Your developer ID for authentication and tracking
Query parameters
idstringRequired
The id of the user to generate a token for.
Responses
200
Token generated.
application/json
tokenstringRequiredExample:
Single-use token to present in the IDENTIFY frame.
OTYwNWFi5ZWQMTAxMjg0Y2Qw.gzrPzZcS3Gy8QDOxbiPRwu30PTB3VxW0eE400
Missing id parameter, or missing/malformed authentication headers.
403
Invalid credentials, or the user does not belong to this developer.
500
Token generation failed.
post/auth/user
POST /auth/user?id=text HTTP/1.1
Host: ws.tryterra.co
x-api-key: YOUR_API_KEY
dev-id: YOUR_API_KEY
Accept: */*
{
"token": "OTYwNWFi5ZWQMTAxMjg0Y2Qw.gzrPzZcS3Gy8QDOxbiPRwu30PTB3VxW0eE"
}Last updated
Was this helpful?