getActiveZoneMinutes
Retrieve Fitbit Active Zone Minutes data for specific dates or periods to monitor exercise intensity and track fitness progress.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | Date in YYYY-MM-DD format. If not specified, will use today. | |
| period | No | Period for data: 1d, 7d, 30d, 1w, 1m |
Input Schema (JSON Schema)
{
"properties": {
"date": {
"description": "Date in YYYY-MM-DD format. If not specified, will use today.",
"type": "string"
},
"period": {
"description": "Period for data: 1d, 7d, 30d, 1w, 1m",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/server.ts:726-767 (handler)The handler function for the 'getActiveZoneMinutes' tool. It formats the input date, constructs the appropriate Fitbit API endpoint based on date and period parameters, fetches the data using the shared makeApiRequest helper, processes the response, and returns formatted JSON or an error.async ({ date, period }) => { try { const formattedDate = formatDate(date); let endpoint = ""; if (period) { endpoint = `/user/-/activities/active-zone-minutes/date/${formattedDate}/${period}.json`; } else { endpoint = `/user/-/activities/active-zone-minutes/date/${formattedDate}/1d.json`; } const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify( { date: formattedDate, activeZones: data["activities-active-zone-minutes"] || [], intraday: data["activities-active-zone-minutes-intraday"] || {}, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }
- src/server.ts:717-724 (schema)Input schema for the 'getActiveZoneMinutes' tool defined using Zod. Includes optional 'date' (YYYY-MM-DD) and 'period' (e.g., 1d, 7d) parameters with descriptions.date: z .string() .optional() .describe("Date in YYYY-MM-DD format. If not specified, will use today."), period: z .string() .optional() .describe("Period for data: 1d, 7d, 30d, 1w, 1m"),
- src/server.ts:714-768 (registration)Registration of the 'getActiveZoneMinutes' tool on the MCP server using server.tool(). Includes the tool name, input schema, and inline async handler function.server.tool( "getActiveZoneMinutes", { date: z .string() .optional() .describe("Date in YYYY-MM-DD format. If not specified, will use today."), period: z .string() .optional() .describe("Period for data: 1d, 7d, 30d, 1w, 1m"), }, async ({ date, period }) => { try { const formattedDate = formatDate(date); let endpoint = ""; if (period) { endpoint = `/user/-/activities/active-zone-minutes/date/${formattedDate}/${period}.json`; } else { endpoint = `/user/-/activities/active-zone-minutes/date/${formattedDate}/1d.json`; } const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify( { date: formattedDate, activeZones: data["activities-active-zone-minutes"] || [], intraday: data["activities-active-zone-minutes-intraday"] || {}, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } } );
- src/server.ts:68-72 (helper)Shared helper function used by getActiveZoneMinutes (and other tools) to format or default the date parameter to YYYY-MM-DD format.function formatDate(date?: string): string { if (date) return date; const today = new Date(); return today.toISOString().split("T")[0]; // YYYY-MM-DD }
- src/server.ts:44-64 (helper)Shared helper function used by getActiveZoneMinutes (and other tools) to make authenticated HTTP requests to the Fitbit API and handle errors.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; }