Terra Docs
Dashboard
  • Docs
  • API Reference
  • Changelog
  • Health & Fitness API
    • REST API Endpoints
    • Supported integrations
    • Event Types
    • Data models
    • Samples
    • Core concepts
    • Destinations
    • Mobile SDK
      • iOS (Swift)
      • Android (Kotlin)
      • React Native
      • Flutter
  • Streaming API
    • REST API Endpoints
    • Supported Integrations
    • Core Concepts
    • Websocket Reference
    • Mobile SDK
      • iOS (Swift)
      • Android (Kotlin)
      • Flutter
      • React Native
  • Teams API - Beta
    • Supported Integrations
    • Core Concepts
    • API Endpoints
    • Event types
Powered by GitBook
On this page
  • Identify Data Schema
  • Identify Type Enum
  • Payload Format
  • Example Payload
  • Opcodes
  • Data Types
  • Close Codes

Was this helpful?

  1. Streaming API

Websocket Reference

PreviousCore ConceptsNextMobile SDK

Last updated 3 months ago

Was this helpful?

Identify Data Schema

Field Name
Type
Description

token

String

Integer

Connection type. Value from the IdentifyType enum.

Identify Type Enum

Name
Value

User (Producer)

0

Developer (Consumer)

1

Payload Format

Field Name
Type
Description

op

Integer

d?

Object

Event data.

uid?*

String

User ID that the event relates to.

seq?*

Long

Sequence number of the payload. Used when replaying missed payloads.

t?*

String

? -> Optional field * -> Only send with payloads of theopcode

Example Payload

{
  "op": 5,
  "d": {
    "ts": "2022-05-04T10:26:11.268507+01:00",
	"val": 95
	},
  "uid": "8e864e3a-979a-4d04-b4e9-b6d020f20ba0",
  "seq": 73,
  "t": "HEART_RATE"
}
{
  "op": 6,
  "d": {
        "val": 95
	},
  "t": "HEART_RATE"
}

Heartbeat

Upon opening a websocket connection to the server, you will immediately be sent an Op 2 HELLO payload containing the heartbeat interval (in milliseconds) that the client should use when sending heartbeat messages to the server.

{
  "op": 2,
  "d": {
    "heartbeat_interval": 40000
  }
}

Heartbeat Acknowledged

{"op": 1} // Sent back to the client by the server every "heartbeat_interval" ms

Opcodes

Name
Value
Description
Sent By

HEARTBEAT

0

Fired periodically by the client to keep the connection alive.

Client

HEARTBEAT_ACK

1

Sent by the server to acknowledge that a heartbeat has been received.

Server

HELLO

2

Sent by the server immediately after connecting. Contains the heartbeat interval for the client to use.

Server

IDENTIFY

3

Sent by the client to complete the handshake with the server. Contains authentication details.

Client

READY

4

Sent by the server once the handshake has been completed. The client will be able to receive/send payloads immediately after this is received.

Server

DISPATCH

5

An event dispatched by the server. Contains details about the event, as well as the data payload for the event.

Server

SUBMIT

6

Sent by the client to notify the server of new data which will then be routed to the correct consumer appropriately.

Client (producer only)

REPLAY

7

Request a replay of payloads after the given lower bound, and optionally before a given upper bound.

Client (consumer only)

Data Types

Name
Description

HEART_RATE

val is the BPM of each reading

STEPS

val the amount of accumulated steps

DISTANCE

val the accumulated distance in meters

FLOORS_CLIMBED

val the accumulated floors climbed

STEPS_CADENCE

val the amount of steps per second taken by the user

SPEED

val the speed in meter per second of the user

ACCELERATION

d the acceleration data of the device. - d[0] -> acceleration in x direction - d[1] -> acceleration in y direction - d[2] -> acceleration in z direction

GYROSCOPE

d the rotation rate of the device. - d[0] -> rotation in x direction - d[1] -> rotation in y direction - d[2] -> rotation in z direction

Close Codes

Code
Reason

1001

Server is shutting down

1007

Invalid or unrecognised JSON data was provided

4000

IDENTIFY payload expected but was not received

4001

Improper token was passed for IDENTIFY

4002

Duplicate connection opened

4003

Multiple IDENTIFY payloads received

4004

Unrecognised opcode was received

Authentication token generated from the

for the payload.

The for the payload.

DISPATCH
appropriate endpoint.
type
Opcode
Data Type