Linking Garmin & Gemini
Gemini has no native Garmin integration. To get your workouts, VO2 max, and HRV into Gemini without running a server or exporting CSVs by hand, you can use a Google Apps Script to pull data from Garmin's Personal API into a Google Sheet every 30 minutes, then attach that sheet to a custom Gemini Gem.
Here is the exact setup.
What you need: A Garmin Connect account, a Google account, and 5 minutes. The script lives inside a single Google Sheet, runs free on Google's servers, and has zero access to the rest of your Google Drive.
Step 1: Get Your Garmin Personal API Key
- Log in to connect.garmin.com in a desktop browser.
- Click your profile avatar (top right) > Account Settings > Personal API Key (on the left menu).
- Click Create Key, accept the terms, choose an expiration period (up to 1 year), and click Create.
- Copy the
GCDC_...key immediately and save it—Garmin only displays it once.
Step 2: Have Gemini Build Your Google Sheet
Instead of creating tabs and typing column headers yourself, let Gemini generate the spreadsheet directly in your Google Drive.
- Open gemini.google.com, click Settings (bottom left) > Extensions, and make sure Google Workspace is toggled On.
- Start a new chat and paste this exact prompt:
Create a new Google Sheet in my Drive named
Garmin_Live_Sync. Rename the first tab toActivitieswith these exact headers in Row 1:Activity ID,Start Time (Local),Name,Type,Duration (min),Distance (km),Avg Pace (min/km),Avg HR,Max HR,Avg Cadence,Aerobic TE,Raw JSON. Create a second tab namedVO2_and_HRVwith these exact headers in Row 1:Date,VO2 Max (Running),HRV Weekly Avg,HRV Last Night,HRV Status.
- Gemini will create the spreadsheet and give you a clickable link. Click it to open your new sheet.
Step 3: Paste the Sync Script & Set the Timer
Garmin's Personal API uses two-step authentication: you POST your GCDC_... key to get a 24-hour JWT string (returned as plain text, not JSON), then pass that token as a Bearer header to the activity and health endpoints.
- In
Garmin_Live_Sync, click Extensions > Apps Script. - Delete
function myFunction() {}and paste the complete script below. ReplaceYOUR_GCDC_API_KEYon line 1 with your key from Step 1:
const GARMIN_API_KEY = 'YOUR_GCDC_API_KEY';
const BASE_URL = '[https://personal.connectapi.garmin.com](https://personal.connectapi.garmin.com)';
const TOKEN_URL = `${BASE_URL}/personalapitoken-service/personal-api/personal-api-key/token`; function syncGarminLive() { // 1. Exchange Personal API Key for raw 24-hour JWT access token const tokenRes = UrlFetchApp.fetch(TOKEN_URL, { method: 'post', headers: { 'Authorization': 'ApiKey ' + GARMIN_API_KEY } }); const accessToken = tokenRes.getContentText().trim(); const authHeaders = { 'Authorization': 'Bearer ' + accessToken }; const today = new Date(); const sevenDaysAgo = new Date(today.getTime() - 7 * 86400000); const fmtDate = (d) => d.toISOString().split('T')[0]; const startDate = fmtDate(sevenDaysAgo); const endDate = fmtDate(today); const ss = SpreadsheetApp.getActiveSpreadsheet(); // 2. Pull last 20 activities const actRes = UrlFetchApp.fetch( `${BASE_URL}/activitylist-service/activities/search/activities?limit=20&start=0`,
{ method: 'get', headers: authHeaders }
);
writeActivities(ss, JSON.parse(actRes.getContentText()));
// 3. Pull last 7 days of VO2 Max & HRV
const vo2Res = UrlFetchApp.fetch(
`${BASE_URL}/metrics-service/metrics/maxmet/daily/${startDate}/${endDate}`, { method: 'get', headers: authHeaders, muteHttpExceptions: true } ); const hrvRes = UrlFetchApp.fetch( `${BASE_URL}/hrv-service/hrv/daily/${startDate}/${endDate}`,
{ method: 'get', headers: authHeaders, muteHttpExceptions: true }
);
writeRecoveryMetrics(ss, vo2Res.getContentText(), hrvRes.getContentText());
}
function writeActivities(ss, activities) {
const sheet = ss.getSheetByName('Activities');
const existingIds = sheet.getLastRow() > 1
? sheet.getRange(2, 1, sheet.getLastRow() - 1, 1).getValues().flat().map(String)
: [];
activities.reverse().forEach(act => {
const id = String(act.activityId);
if (!existingIds.includes(id)) {
const distKm = act.distance ? (act.distance / 1000).toFixed(2) : 0;
const durMin = act.duration ? (act.duration / 60).toFixed(1) : 0;
const pace = (act.distance && act.duration)
? ((act.duration / 60) / (act.distance / 1000)).toFixed(2)
: '';
sheet.appendRow([
id,
act.startTimeLocal || '',
act.activityName || '',
act.activityType?.typeKey || '',
durMin,
distKm,
pace,
act.averageHR || '',
act.maxHR || '',
act.averageRunningCadenceInStepsPerMinute || act.averageBikingCadenceInRevPerMinute || '',
act.aerobicTrainingEffect || '',
JSON.stringify(act)
]);
}
});
}
function writeRecoveryMetrics(ss, vo2Raw, hrvRaw) {
const sheet = ss.getSheetByName('VO2_and_HRV');
const map = {};
try {
const vo2Data = JSON.parse(vo2Raw);
(Array.isArray(vo2Data) ? vo2Data : []).forEach(entry => {
const d = entry.generic?.calendarDate || entry.calendarDate;
if (d) {
map[d] = map[d] || {};
map[d].vo2 = entry.generic?.vo2MaxPreciseValue || entry.generic?.vo2MaxValue || '';
}
});
} catch (e) {}
try {
const hrvParsed = JSON.parse(hrvRaw);
const summaries = hrvParsed.hrvSummaries || (Array.isArray(hrvParsed) ? hrvParsed : []);
summaries.forEach(entry => {
const d = entry.calendarDate;
if (d) {
map[d] = map[d] || {};
map[d].weeklyAvg = entry.weeklyAvg || '';
map[d].lastNight = entry.lastNightAvg || '';
map[d].status = entry.status || '';
}
});
} catch (e) {}
const existingDates = sheet.getLastRow() > 1
? sheet.getRange(2, 1, sheet.getLastRow() - 1, 1).getValues().flat().map(String)
: [];
Object.keys(map).sort().forEach(date => {
const rowValues = [
date,
map[date].vo2 || '',
map[date].weeklyAvg || '',
map[date].lastNight || '',
map[date].status || ''
];
const rowIndex = existingDates.indexOf(date);
if (rowIndex === -1) {
sheet.appendRow(rowValues);
} else {
sheet.getRange(rowIndex + 2, 1, 1, 5).setValues([rowValues]);
}
});
}- Press Cmd + S (or Ctrl + S) to save.
- Click Run in the top toolbar. When Google warns "Google hasn't verified this app", click Advanced > Go to Untitled project (unsafe) > Allow. Your sheet immediately pulls your recent workouts, VO2 max, and HRV.
- Click the Triggers icon (alarm clock on the left sidebar) > + Add Trigger.
- Set Function to
syncGarminLive, Event source toTime-driven, Type toMinutes timer, and Interval toEvery 30 minutes. Click Save.
Step 4: Link the Sheet to a Gemini Notebook
- Open gemini.google.com, click Notebooks in the left sidebar, and select + New Notebook.
- Name it
Garmin Coach. - Under Knowledge, click + > Add from Drive and select
Garmin_Live_Sync(plus your training plan spreadsheet if you have one). - Paste your heart rate zones, weekly schedule, and this rule into Instructions:
Always read Garmin_Live_Sync (tabs: Activities and VO2_and_HRV) from Google Drive before giving training advice or prescribing workouts. - Click Save, and confirm the Google Workspace extension is toggled on in Gemini Settings.
Once your watch syncs to your phone, new sessions hit the sheet within 30 minutes. Open your Gem and ask:
Pull my latest workouts and HRV from Garmin_Live_Sync, compare them against my plan, and tell me what to adjust for tomorrow.