Skip to main content
When a gym starts with TechnicallyFit it often has months of visits and training on record already. This sample sends that history through POST /v1/events:bulk with the TypeScript SDK. The same pattern works for a nightly import from a door system or a training app.

Set up the location and its equipment first

A visit names a location by its external_id, so the location must exist before its history arrives. PUT creates it or updates it in place, and the equipment calls replace the whole list each time, so a rerun leaves the same state.
The key needs locations:write for these calls and events:write for the history.

Key every event by what it is

Give each event a key built from the teammate and the thing it records, never a random one. A visit is keyed by the teammate and the day; a set by the teammate, the day and the set. Run the import again and every event answers duplicate, so nothing is stored twice.
  • at is an RFC 3339 time with an offset. Work it out from the location’s own time zone, so a 7 o’clock visit counts at 7 o’clock there.
  • location is the external_id of one of your locations. See Locations and equipment.
  • A logged set is keyed by its source.route and source.record_id instead of an idempotency key. See Sending events.

Send it and read the results

sendBulk checks every event first, then splits the list into requests within the count and size limits. Each event gets its own result.
A first run answers accepted for each event. A second run with the same history answers duplicate for each one. A rejected event carries its reason, such as unknown_location or consent_required; fix it and send that event again with the same key.

What the gym sees

Visits feed the traffic figures and the at-risk list, each for the teammates who allow it. Traffic withholds any hour with fewer than five teammates, so history spread thinly over many hours shows less than history that clusters at the gym’s real peaks. The at-risk check compares a teammate’s last two weeks with the eight before, so send at least ten weeks to see it work.