Skip to content

Add a Garmin Connect template on Garmin's Personal API - #338

Merged
tnkuehne merged 6 commits into
mainfrom
feat/garmin-connect-template
Nov 23, 2026
Merged

tnkuehne merged 6 commits into
mainfrom
feat/garmin-connect-template

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Change

A Garmin Connect template.

  • Each user connects their own Garmin account with a Personal API key they create on Garmin Connect. Garmin's Personal API has no OAuth.
  • The app checks the key with Garmin, stores it encrypted with the app's keys and never shows it again.
  • The app issues a 24-hour access token from the key when it needs one. It reuses the token until shortly before it expires and issues a new one once when Garmin refuses it. A key Garmin rejects makes methods return reconnect_required until the user saves a new one.
  • 28 typed read methods: activities and their original files, daily summaries, steps, stress, hydration, sleep, heart rate, HRV, Body Battery, SpO2, VO2 max, fitness age, weight, nutrition, menstrual cycle data and profile settings.
  • template.md quotes Garmin's FAQ on who the Personal API is for.

Generator.

  • Garmin's description gives its operations no IDs. Rules can now list an operation by method and path, such as GET /hrv-service/hrv/{calendarDate}.
  • Garmin publishes the description only inside its Swagger page's script. A template's scripts/operations.ts can export download to read it from there. templates/garmin-connect/scripts/openapi.ts cuts the description out of the script without running it.
  • Templates whose methods only read no longer receive the approval files.

Tests

  • Template tests against a fake Garmin server cover connecting with a key and reading data, token reuse, a new token after expiry or a 401, a deleted key and a refused key, the round trip from the connections page, disconnecting, Garmin errors, throttling and responses over 8 MiB. tests/types.ts checks the generated types.
  • Generator test for operations listed by method and path.
  • Ran pnpm check, the generator tests and the template tests.
  • Not yet run against Garmin's live API. The token format follows Garmin's official Python client.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issue was found.

Summary

Adds a Garmin Connect template with 28 typed read methods and a separate saved connection for each user.

  • Each user connects a Garmin key for their own account.
  • Garmin data reads come through one typed service.
  • The generator can read Garmin's embedded API description.

No new actionable issues were found. The four previous unnumbered findings are addressed.

Diagram

sequenceDiagram
  participant User
  participant App as Garmin template
  participant DB as App database
  participant Garmin
  User->>App: Save Personal API key
  App->>Garmin: Issue token and read profile
  Garmin-->>App: Token and account name
  App->>DB: Save encrypted key and token
  User->>App: Call a read method
  App->>DB: Read saved token
  opt Token expires soon or was refused
    App->>DB: Claim renewal
    App->>Garmin: Issue replacement token
    App->>DB: Save encrypted token
  end
  App->>Garmin: Read user's data
  Garmin-->>App: Data or error
  App-->>User: Typed result
Loading

Reviews (3) · Last reviewed commit: "Regenerate the Garmin Connect template w..." · Reviewed by Greptile

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs d2cfe2b Nov 23 2026, 02:59 PM

…ns published inside other documents

Garmin's Personal API description gives its operations no IDs and is
published only inside its Swagger page's script. Rules now list such
operations by method and path, and a template's scripts/operations.ts can
export download to read the description from where its provider publishes it.
Templates whose methods only read no longer receive the approval files.
Each user connects their own Garmin account with a Personal API key they
create on Garmin Connect. The key is checked with Garmin, stored encrypted
with the app's keys and never shown again. The template issues an access
token from the key when needed, reuses it until shortly before it expires
and issues a new one once when Garmin refuses it.

28 typed read methods are generated from the OpenAPI description on
Garmin's Swagger page: activities and their original files, daily
summaries, sleep, heart rate, HRV, Body Battery, SpO2, VO2 max, fitness
age, weight, nutrition, menstrual cycle data and profile settings.
The Garmin Connect template connects with a Personal API key and has no
OAuth client.
…en requests

The key form now ends on the app's own page, which navigates back to
Widefleet: the app's form-action policy allows only its own origin, and
Chromium applies it to the redirects after a form submission.

A Garmin request that cannot be sent while saving a key shows the retry
notice and keeps the way back to Widefleet, as other outages do.

One request at a time issues a user's new token, holding the row for a
short lease; overlapping requests wait for the token it saves instead of
each requesting their own.
@tnkuehne
tnkuehne force-pushed the feat/garmin-connect-template branch from 3337e52 to d2cfe2b Compare November 23, 2026 14:57
@tnkuehne
tnkuehne merged commit 8efdb49 into main Nov 23, 2026
15 checks passed
@tnkuehne
tnkuehne deleted the feat/garmin-connect-template branch November 23, 2026 15:08
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.

1 participant