clockify-tracker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClockify time tracking (REST API)
Clockify时间追踪(REST API)
Integrate with Clockify using HTTPS requests to . Do not assume any local binary exists.
https://api.clockify.me/api/v1clockify_tracker通过向发送HTTPS请求与Clockify集成。不要假设本地存在二进制文件。
https://api.clockify.me/api/v1clockify_trackerEnvironment
环境
| Variable | Required | Purpose |
|---|---|---|
| Yes | API key from Clockify (Profile → API) |
| No | Local offset from UTC in whole hours (e.g. |
| 变量 | 是否必填 | 用途 |
|---|---|---|
| 是 | 来自Clockify的API密钥(个人资料 → API) |
| 否 | 本地时间与UTC的偏移量(以整小时为单位,例如阿根廷为 |
Authentication
认证
Every request:
- Header:
X-Api-Key: <CLOCKIFY_API_KEY> - Header: (for POST bodies)
Content-Type: application/json
Never paste the API key into chat; use the environment variable in the tool/shell you run.
每个请求需包含:
- 请求头:
X-Api-Key: <CLOCKIFY_API_KEY> - 请求头:(用于POST请求体)
Content-Type: application/json
切勿在聊天中粘贴API密钥;请在运行的工具/Shell中使用环境变量。
Endpoints (mirror of former CLI behavior)
端点(与原CLI行为一致)
List workspaces
列出工作区
GET /workspacesReturns a JSON array of workspaces; each item includes and .
idnameGET /workspaces返回工作区的JSON数组;每个条目包含和。
idnameList projects in a workspace
列出工作区中的项目
GET /workspaces/{workspaceId}/projects?page-size=5000Returns a JSON array of projects; each item includes and .
idnameFlow: If the user might have multiple workspaces, call first and let them pick (or use the only one). Then list projects for the chosen .
GET /workspacesworkspaceIdGET /workspaces/{workspaceId}/projects?page-size=5000返回项目的JSON数组;每个条目包含和。
idname流程: 如果用户可能有多个工作区,先调用,让用户选择(或使用唯一的那个)。然后为选中的列出项目。
GET /workspacesworkspaceIdCreate a time entry
创建时间条目
POST /workspaces/{workspaceId}/time-entriesJSON body (fields aligned with the previous CLI):
| Field | Required | Notes |
|---|---|---|
| Yes | ISO 8601 UTC string, e.g. |
| Yes | Work description |
| No | Boolean, default |
| No | ISO 8601 UTC; omit for open-ended entry |
| No | Clockify project id |
POST /workspaces/{workspaceId}/time-entriesJSON请求体(字段与之前的CLI对齐):
| 字段 | 是否必填 | 说明 |
|---|---|---|
| 是 | ISO 8601格式的UTC字符串,例如 |
| 是 | 工作描述 |
| 否 | 布尔值,省略时默认 |
| 否 | ISO 8601格式的UTC时间;留空表示未结束的条目 |
| 否 | Clockify项目ID |
Converting user-local HH:mm
to UTC start
/ end
HH:mmstartend将用户本地HH:mm
时间转换为UTC格式的start
/end
HH:mmstartendWhen the user gives local time as (and optional , default today in their locale intent):
HH:mmYYYY-MM-DD- Parse date (year, month, day) and time parts
D,hour.minute - Let be the offset in hours from UTC for that local zone:
tzOffsetfor UTC+5,+5for UTC-3. Use-3if set (integer hours); otherwise infer from the user (e.g. Argentina →CLOCKIFY_TZ_OFFSET) or from context.-3 - Build UTC instant:
then normalize into a proper UTC
utc_hour = hour - tzOffseton calendar dayDateTime(carry overflow across day boundaries as needed), and serialize withD(ISO 8601 UTC).Z
Examples:
- Local on
09:00,2025-03-10→ UTC hourtzOffset = -3→9 - (-3) = 12.2025-03-10T12:00:00.000Z - If the user already provides full ISO strings with and timezone/
T, pass them through without this conversion.Z
当用户提供本地时间(可选,默认是用户所在时区的当天)时:
HH:mmYYYY-MM-DD- 解析日期(年、月、日)和时间部分
D、hour。minute - 设为本地时区与UTC的小时偏移量:UTC+5为
tzOffset,UTC-3为+5。如果已设置-3(整数小时)则使用该值;否则从用户信息(例如阿根廷→CLOCKIFY_TZ_OFFSET)或上下文推断。-3 - 构建UTC时间:
然后将其规范化为日历日
utc_hour = hour - tzOffset上的正确UTCD(必要时跨日边界处理溢出),并以DateTime结尾的ISO 8601 UTC格式序列化。Z
示例:
- 本地时间的
2025-03-10,09:00→ UTC小时tzOffset = -3→9 - (-3) = 12。2025-03-10T12:00:00.000Z - 如果用户已提供包含及时区/
T的完整ISO字符串,直接使用无需转换。Z
Multiple calendar days
跨多个日历日
For ranges ("March 2–6") or discrete lists ("March 23, 24, 25, 26 and 27"), create one POST per day with the same local times and the appropriate date for each (and if any). When no year is provided, assume the current calendar year.
startend对于时间范围(如“3月2日至6日”)或离散日期列表(如“3月23、24、25、26和27日”),每天创建一个POST请求,使用相同的本地时间和对应日期的(如有则同理)。如果未提供年份,默认使用当前日历年度。
startendOperational flow
操作流程
- Confirm is available to the execution environment.
CLOCKIFY_API_KEY - If workspace is unknown: ; resolve
GET /workspaces.workspaceId - If project is needed: ; resolve
GET /workspaces/{workspaceId}/projects?page-size=5000.projectId - Collect description, start (and optional end), date if needed, and timezone offset if not obvious.
- Build JSON and .
POST /workspaces/{workspaceId}/time-entries - Show the API JSON response or a clear error (status code + body).
- 确认执行环境中已配置。
CLOCKIFY_API_KEY - 如果工作区未知:调用;确定
GET /workspaces。workspaceId - 如果需要项目:调用;确定
GET /workspaces/{workspaceId}/projects?page-size=5000。projectId - 收集描述、开始时间(可选结束时间)、所需日期,以及不明确的时区偏移量。
- 构建JSON并发送请求。
POST /workspaces/{workspaceId}/time-entries - 显示API的JSON响应或清晰的错误信息(状态码+响应体)。
Errors
错误处理
On non-success status, read the response body and adjust (invalid id, permissions, malformed body). Official reference: Clockify API documentation.
收到非成功状态码时,读取响应体并调整请求(如无效ID、权限问题、请求体格式错误)。官方参考:Clockify API文档。