Garmin Connect CLI
This skill provides access to Garmin Connect health and fitness data through the gc CLI.
Setup
- 1. Install via Homebrew tap:
CODEBLOCK0
- 2. Authentication:
CODEBLOCK1
- 3. Verify connection:
CODEBLOCK2
Date Shortcuts
Most commands accept a date shortcut as first argument:
- -
today — current date - INLINECODE2 — previous date
- INLINECODE3 — last 7 days (returns a date range)
- INLINECODE4 — last 30 days (returns a date range)
- INLINECODE5 — specific date
For command groups with subcommands (activities, body, stress, heart, menstrual),
use --date on the parent command to avoid argument conflicts.
Alternatively use --date, --start/--end flags.
Output
All data commands support:
- -
--format json for machine-readable output (default: table) - INLINECODE12 to write to a file
Always use --format json when parsing output programmatically.
Usage
CODEBLOCK3 json
{"type":"interval","duration":1200,"target":"hr_zone:2"}
CODEBLOCK4
Examples
Get today's health summary as JSON:
CODEBLOCK5
Get last week's steps as JSON for analysis:
CODEBLOCK6
Find the user's most recent run:
CODEBLOCK7
Call a raw Garmin Connect API endpoint:
CODEBLOCK8
Get detailed info about a specific activity:
CODEBLOCK9
Download an activity as GPX:
CODEBLOCK10
Check training readiness and HRV:
CODEBLOCK11
Get sleep and body battery for yesterday:
CODEBLOCK12
Workout creation (concise)
- - Prefer
--file with a Garmin-shaped JSON payload. - Get a valid payload by exporting an existing workout:
gc workouts get WORKOUT_ID --format json > workout.json
- - If using flags,
--steps can be the exact workoutSteps JSON array from the API
or a shorthand array with
type,
duration (seconds), and optional
target (e.g.
hr_zone:2).
- -
--sport-id is optional when --sport is provided; the CLI resolves the id from activity types.
Garmin workout shape (minimal example):
CODEBLOCK14
Example creations:
CODEBLOCK15
How to discover format and valid values for workout creation:
- - Sport type keys/ids (used in
sportType):
-
gc activities types --format json
- - Workout step/target enums are not hardcoded in the CLI.
- Export an existing workout and reuse the exact values:
gc workouts get WORKOUT_ID --format json
- Use the returned
stepType,
endCondition, and
targetType fields verbatim.
List devices and get solar data:
CODEBLOCK17
Garmin Connect CLI
该技能通过 gc 命令行工具提供对 Garmin Connect 健康和健身数据的访问。
设置
- 1. 通过 Homebrew tap 安装:
bash
brew tap voydz/homebrew-tap
brew install garmin-cli
- 2. 身份验证:
bash
gc login --email user@example.com --password secret
# 使用多因素认证:
gc login --email user@example.com --password secret --mfa 123456
- 3. 验证连接:
bash
gc status
日期快捷方式
大多数命令接受日期快捷方式作为第一个参数:
- - today — 当前日期
- yesterday — 前一天
- week — 最近7天(返回日期范围)
- month — 最近30天(返回日期范围)
- YYYY-MM-DD — 特定日期
对于包含子命令的命令组(活动、身体、压力、心率、月经),
使用父命令上的 --date 以避免参数冲突。
或者使用 --date、--start/--end 标志。
输出
所有数据命令支持:
- - --format json 用于机器可读输出(默认:table)
- --output FILE 用于写入文件
在程序化解析输出时始终使用 --format json。
用法
bash
身份验证
gc login --email EMAIL --password PASS [--mfa CODE | --wait-mfa]
gc logout
gc status
gc status --profile
每日健康
gc health today
gc steps today
gc steps week
gc steps --weekly --weeks N
gc steps --start DATE --end DATE
gc floors today
gc intensity today
gc intensity --weekly --weeks N
gc events today
心率
gc heart --date today
gc heart resting --date today
睡眠
gc sleep today
压力与身体电量
gc stress --date today
gc stress --weekly --weeks N
gc stress all-day --date today
gc battery today
gc battery --start DATE --end DATE
gc battery --events today
生命体征
gc respiration today
gc spo2 today
gc blood-pressure today [--end DATE]
gc lifestyle today
水分
gc hydration today
活动
gc activities # 列出最近活动(默认20条)
gc activities --limit N --offset N --type TYPE
gc activities --start DATE --end DATE [--type TYPE]
gc activities --date today # 指定日期的活动
gc activities last # 最近一次活动
gc activities get ID # 按ID获取活动摘要
gc activities count # 总计数
gc activities details ID
gc activities splits ID
gc activities typed-splits ID
gc activities split-summaries ID
gc activities weather ID
gc activities hr-zones ID
gc activities power-zones ID
gc activities exercise-sets ID
gc activities types # 列出所有活动类型
gc activities gear ID # 活动使用的装备
gc activities progress --start DATE --end DATE --metric distance|duration|elevation
gc activities download ID --format fit|tcx|gpx|kml|csv [-o FILE]
gc activities upload FILE # .fit, .gpx, .tcx
身体与体重
gc body --date today [--end DATE]
gc body weighins --date today
gc body weighins --start DATE --end DATE
高级指标
gc metrics # 指标摘要
gc metrics --date today
gc metrics vo2max today
gc metrics hrv today
gc metrics training-readiness today
gc metrics morning-readiness today
gc metrics training-status today
gc metrics fitness-age today
gc metrics race-predictions
gc metrics race-predictions --start DATE --end DATE --type daily|monthly
gc metrics endurance-score today [--end DATE]
gc metrics hill-score today [--end DATE]
gc metrics lactate-threshold # 最新
gc metrics lactate-threshold --no-latest --start DATE --end DATE --aggregation daily|weekly|monthly|yearly
gc metrics cycling-ftp
注意:gc metrics 摘要首先从每日最大代谢当量解析 vo2max,
当所选日期没有新的最大代谢当量样本时,回退到 training-status.mostRecentVO2Max。
设备
gc devices # 列出所有设备
gc devices last-used
gc devices primary
gc devices settings DEVICE_ID
gc devices alarms
gc devices solar DEVICE_ID today [--end DATE]
目标、记录、徽章与挑战
gc records
gc goals [--status active|future|past] [--limit N]
gc badges earned
gc badges available
gc badges in-progress
gc challenges adhoc [--start N --limit N]
gc challenges badge [--start N --limit N]
gc challenges available [--start N --limit N]
gc challenges non-completed [--start N --limit N]
gc challenges virtual [--start N --limit N]
装备
gc gear --user-profile USER
PROFILENUMBER # 列出装备(配置文件编号来自 gc status --profile)
gc gear defaults USER
PROFILENUMBER
gc gear stats GEAR_UUID
gc gear activities GEAR_UUID [--limit N]
训练与训练计划
gc workouts [--start N --limit N]
gc workouts get WORKOUT_ID
gc workouts download WORKOUT_ID [-o FILE]
gc workouts scheduled WORKOUT_ID
gc workouts create --file workout.json
gc workouts create --name 训练名称 --sport cycling --steps [{type:warmup,duration:600},{type:interval,duration:1200,target:hr_zone:2},{type:cooldown,duration:600}]
gc workouts update WORKOUT_ID --file workout.json
gc workouts update WORKOUT_ID --name 训练名称 --sport cycling --steps [{type:warmup,duration:600},{type:interval,duration:1200},{type:cooldown,duration:600}]
gc workouts delete WORKOUT_ID
gc training-plans
gc training-plans get PLAN_ID
gc training-plans adaptive PLAN_ID
训练步骤 JSON 模式(--steps)
--steps 需要一个步骤对象的 JSON 数组。每个步骤可以是简写形式或 Garmin 格式。
简写步骤示例:
json
{type:interval,duration:1200,target:hr_zone:2}
支持的简写字段:
- - type:warmup、interval、recovery、cooldown、rest、repeat
- duration:秒(表示 endCondition = time)
- target:hrzone:2、powerzone:3、pacezone:4、heartrate:150、power:220、cadence:90、no_target
Garmin 格式字段(可选):
- - stepType:{stepTypeKey:warmup}(或任何 Garmin stepType 对象)
- stepOrder:整数
- endCondition:{conditionTypeKey:time|distance|calories|heart_rate|cadence|power|iterations}
- endConditionValue:数字
- targetType:{workoutTargetTypeKey:no.target|heart.rate|power|speed|cadence|open|heart.rate.zone|power.zone|pace.zone}
- targetValue:数字
对于高级 Garmin 负载(重复组、嵌套步骤等),建议使用 --file 配合完整的 Garmin 模式。
月经周期
gc menstrual --date today
gc menstrual calendar --start DATE --end DATE
gc menstrual pregnancy
原始 API
gc api /biometric-service/biometric/latestFunctionalThresholdPower/CYCLING
gc api /metrics-service/metrics/maxmet/daily/DATE/DATE
gc api /metrics-service/metrics/trainingstatus/aggregated/DATE
gc api --method POST --body {foo:bar} /some/endpoint
示例
以 JSON 格式获取今日健康摘要:
bash
gc health today --format json
以 JSON 格式获取上周步数用于分析:
bash
gc steps week --format json
查找用户最近的跑步活动:
bash
gc activities --limit 5 --type running --format json
调用原始 Garmin Connect API 端点:
bash
gc api /biometric-service/biometric/latestFunctionalThresholdPower/CYCLING
gc api /metrics-service/metrics/maxmet/daily/2026-03-03/2026-03-03
gc api /metrics-service/metrics/trainingstatus/aggregated/2026-03-03
gc api --method POST --body {foo:bar} /some/endpoint