getLifetimeStats
Retrieve comprehensive lifetime health and fitness statistics from your Fitbit data to track long-term progress and trends.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:474-506 (handler)Inline handler and registration for the 'getLifetimeStats' tool. Fetches lifetime and best activity statistics from the Fitbit API endpoint '/user/-/activities.json' using the shared makeApiRequest helper, formats as JSON, and handles errors.server.tool("getLifetimeStats", {}, async () => { try { const endpoint = "/user/-/activities.json"; const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify( { lifetime: data.lifetime || {}, best: data.best || {}, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } });
- src/server.ts:44-64 (helper)Shared helper function that performs authenticated HTTP requests to the Fitbit API, used by getLifetimeStats and other tools.async function makeApiRequest(endpoint: string): Promise<any> { try { const url = `${baseUrl}${endpoint}`; const response = await fetch(url, { headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/json", }, }); if (!response.ok) { throw new Error( `Fitbit API error: ${response.status} ${response.statusText}` ); } return await response.json(); } catch (error) { console.error(`Error making request to ${endpoint}:`, error); throw error; }