Skip to content

[AI-authored] Fix #146: migrate Tandem Source sync from reportsfacade to bff endpoints#149

Open
craigpress wants to merge 1 commit into
jwoglom:masterfrom
craigpress:fix/tandem-source-bff-endpoints
Open

[AI-authored] Fix #146: migrate Tandem Source sync from reportsfacade to bff endpoints#149
craigpress wants to merge 1 commit into
jwoglom:masterfrom
craigpress:fix/tandem-source-bff-endpoints

Conversation

@craigpress

Copy link
Copy Markdown

Summary

Fixes #146. Tandem retired the api/reports/reportsfacade/* endpoints on 2026-06-30 (HTTP 404), breaking all Tandem Source sync. They are replaced by api/reports/bff/*, which return JSON instead of the legacy binary event blob. This migrates the three affected calls.

Important

This PR was written by an AI (Claude), at the request of a tconnectsync user whose child's pump sync broke. It has been tested against a live account (below) but should be reviewed carefully by a human before merging, since it handles insulin dosing data. You mentioned in #146 that you're already working on a fix — please treat this as a reference/starting point, not a rubber-stamp. Happy to adjust it however you'd like, or feel free to cherry-pick.

Changes

  • api_headers() — send Origin/Referer = source.tandemdiabetes.com. The BFF WAF returns HTTP 403 for the old tconnect.tandemdiabetes.com origin.
  • pump_event_metadata()GET api/reports/bff/pumper/{pumperId}, remapped to the legacy per-pump dict shape. The BFF lists every pump ever on the account (including entries with null / placeholder-future dates), so it filters to the pump(s) uploaded in the last 30 days. Reconstructs lastUpload.settings (tDependentSegstimeDependentSegments, plus the flattened CGM alert thresholds) so UpdateProfiles / PumpSettings keep working unchanged.
  • pump_events_raw() / pump_events()GET api/reports/bff/pump-logs/{deviceId}?pumperId=&startDate=&endDate=&eventIds= (ISO-8601 datetimes), then build native eventparser objects from the JSON.
  • eventparser/json_events.py (new) — generic JSON→eventparser builder. For each eventCode it looks up the eventparser dataclass and maps eventProperties keys to fields by normalizing names (strip a trailing Raw, lowercase); integer-bitmask arrays are folded to ints. Event timestamps are reconstructed from pumpDateTime to land on the identical instant as the binary path. No unit conversion happens here — the downstream processors still do milliunit→unit, carbratio * 0.001, etc., unchanged.

Why a generic builder

Rather than hand-map ~30 event classes, the builder derives each mapping from the dataclass via introspection. The JSON eventProperties names line up with the dataclass fields under the normalize rule (e.g. commandedRatecommandedRate, insulinDeliveredinsulindelivered, bgBG, completionStatuscompletionstatusRaw, carbRatiocarbratioRaw). Unknown event codes fall back to a bare RawEvent, matching the binary Event().

Testing

Tested against a live US-region account with --pretend (no writes), --features covering everything + fetch-all-events:

  • Read 1320 events from BFF pump-logs, classified as {BASAL: 555, CGM_READING: 557, CGM_ALERT: 11, USER_MODE: 4, BOLUS: 68, BASAL_SUSPENSION: 1, ALARM: 2, BASAL_RESUME: 1}.
  • Basal rates, boluses (e.g. 5.17U / 31g), and the full multi-segment profile decode to the same values the binary path produced; compare_profiles reports "up to date" against the profile tconnectsync had previously written from binary data.
  • Full run completes cleanly (Processed 609 events, no traceback).

Not covered (reviewer should check): EU region (no account to test), and extended/combo-bolus edge cases beyond those that appeared in the test window.

🤖 Generated with Claude Code

…om#146)

Tandem retired the api/reports/reportsfacade/* endpoints on 2026-06-30,
returning HTTP 404 and breaking all sync. They are replaced by
api/reports/bff/* which return JSON instead of the legacy binary event blob.

Changes:
- api_headers(): send Origin/Referer = source.tandemdiabetes.com (the BFF WAF
  returns HTTP 403 for the old tconnect origin).
- pump_event_metadata(): fetch api/reports/bff/pumper/{pumperId} and remap to the
  legacy per-pump dict shape, including a reconstructed lastUpload.settings
  (tDependentSegs <- timeDependentSegments) for profile sync. Filters to the
  active pump(s), since the BFF lists all historical pumps on the account.
- pump_events_raw()/pump_events(): fetch api/reports/bff/pump-logs/{deviceId} and
  build native eventparser objects from the JSON.
- eventparser/json_events.py (new): build eventparser dataclasses from BFF JSON by
  normalizing eventProperties keys to dataclass field names; event timestamps are
  reconstructed to match the binary path exactly.

Tested against a live US-region account: all event classes (basal, bolus, CGM,
suspend/resume, alarms, user-mode) parse; basal/bolus/profile values match the
prior binary-path output; profile comparison reports "up to date".

NOTE: This change was written by an AI (Claude) at a user's request and should
receive human review before merging, as it handles insulin dosing data.

Co-Authored-By: Claude <noreply@anthropic.com>
@jwoglom

jwoglom commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Hey @craigpress - can you please try the 'dev' branch, I have been iterating there throughout the evening to try and get the new API working, adding e2e tests as I go.

@craigpress

craigpress commented Jul 1, 2026 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"TandemSourceApi HTTP 404" - Requires Migration to tconnectsync v3.0.0

2 participants