getUserTimeEntries
Retrieve time entries for a specific user from Clockify. Filter by date range using optional start and end parameters in ISO8601 format.
Instructions
List time entries for a specified user. Optional: start, end (ISO8601).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userId | Yes | User ID | |
| start | No | Start date (ISO8601, optional) | |
| end | No | End date (ISO8601, optional) |
Implementation Reference
- src/handlers.ts:240-265 (handler)The handler logic for the 'getUserTimeEntries' tool. It extracts userId, optional start and end dates from arguments, constructs the Clockify API URL for the user's time entries, fetches the data, and returns it as JSON text.case "getUserTimeEntries": { const { userId: targetUserId, start, end, } = request.params.arguments || {}; if (!targetUserId) { throw new Error("userId is required"); } let url = `/workspaces/${workspaceId}/user/${targetUserId}/time-entries`; const params = []; if (typeof start === "string" && start) params.push(`start=${encodeURIComponent(start)}`); if (typeof end === "string" && end) params.push(`end=${encodeURIComponent(end)}`); if (params.length) url += `?${params.join("&")}`; const entries = await clockifyFetch(url); return { content: [ { type: "text", text: JSON.stringify(entries, null, 2), }, ], }; }
- src/handlers.ts:85-103 (schema)The input schema and description for the 'getUserTimeEntries' tool, defined in the listToolsHandler response.name: "getUserTimeEntries", description: "List time entries for a specified user. Optional: start, end (ISO8601).", inputSchema: { type: "object", properties: { userId: { type: "string", description: "User ID" }, start: { type: "string", description: "Start date (ISO8601, optional)", }, end: { type: "string", description: "End date (ISO8601, optional)", }, }, required: ["userId"], }, },
- src/handlers.ts:13-32 (helper)Helper function used by the handler to make authenticated API calls to Clockify, including error handling.async function clockifyFetch(endpoint: string, options: RequestInit = {}) { const apiKey = getApiKey(); const baseUrl = "https://api.clockify.me/api/v1"; const url = endpoint.startsWith("http") ? endpoint : `${baseUrl}${endpoint}`; const headers = { "X-Api-Key": apiKey, "Content-Type": "application/json", ...(options.headers || {}), }; const response = await fetch(url, { ...options, headers }); if (!response.ok) { const text = await response.text(); console.error( `[Error] Clockify API ${url} failed: ${response.status} ${text}`, ); throw new Error(`Clockify API error: ${response.status} ${text}`); } return response.json(); }
- src/index.ts:43-43 (registration)Registration of the listToolsHandler, which exposes the tool schema including getUserTimeEntries.server.setRequestHandler(ListToolsRequestSchema, listToolsHandler);
- src/index.ts:49-49 (registration)Registration of the callToolHandler, which dispatches to the getUserTimeEntries case.server.setRequestHandler(CallToolRequestSchema, callToolHandler);