getBadges
Retrieve earned Fitbit achievement badges to track fitness milestones and monitor progress toward health goals.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "getBadges"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:799-824 (handler)The handler function for the 'getBadges' tool, registered inline. It fetches badges data from the Fitbit API endpoint '/user/-/badges.json' using the shared makeApiRequest helper and returns formatted JSON or an error.
server.tool("getBadges", {}, async () => { try { const endpoint = "/user/-/badges.json"; const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }); - src/server.ts:44-65 (helper)Shared helper function used by getBadges (and other tools) to make authenticated API requests to Fitbit endpoints.
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; } } - src/server.ts:799-824 (registration)Registration of the getBadges tool with empty input schema and inline handler.
server.tool("getBadges", {}, async () => { try { const endpoint = "/user/-/badges.json"; const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } });