时间记录

切换计时

POST /v1/time-entries/switch

写请求需要 Idempotency-Key,填写一个 UUID。同一次操作重试保留原 key、正文和 etag;结果保留 30 天,超过期限先核对数据,不要盲目重试。兼容原时间戳:UUID 格式。

start 不停止已有计时;switch 使用 expectedCurrentId/expectedCurrentEtag 原子切换;使用模板时需提供 presetEtag。

请求参数

Idempotency-Key

header · 必填

写请求需要 Idempotency-Key,填写一个 UUID。同一次操作重试保留原 key、正文和 etag;结果保留 30 天,超过期限先核对数据,不要盲目重试。兼容原时间戳:UUID 格式。

类型: string

完整 JSON Schema
{
  "type": "string"
}

请求体

必填

application/json

类型: object | object

字段类型必填说明与约束
$ (anyOf 1)object否{"additionalProperties":false}
$ (anyOf 1).startTimestring否开始时间,带时区的 ISO 8601 {"format":"date-time"}
$ (anyOf 1).detailstring | null否记录详情
$ (anyOf 1).detail (anyOf 1)string否{"maxLength":65536}
$ (anyOf 1).detail (anyOf 2)null否
$ (anyOf 1).notestring | null否备注
$ (anyOf 1).note (anyOf 1)string否{"maxLength":65536}
$ (anyOf 1).note (anyOf 2)null否
$ (anyOf 1).projectIdstring | null否项目 ID;无项目为 null
$ (anyOf 1).projectId (anyOf 1)string否{"minLength":1,"maxLength":512}
$ (anyOf 1).projectId (anyOf 2)null否
$ (anyOf 1).tagIdsarray<string>否标签 ID;GET 筛选用逗号分隔,正文用数组 {"maxItems":100}
$ (anyOf 1).tagIds[]string否{"minLength":1,"maxLength":512}
$ (anyOf 1).expectedCurrentIdstring | null否预期当前计时 ID;无计时用 null
$ (anyOf 1).expectedCurrentId (anyOf 1)string否{"minLength":1,"maxLength":512}
$ (anyOf 1).expectedCurrentId (anyOf 2)null否
$ (anyOf 1).expectedCurrentEtagstring否预期当前计时的 ETag {"maxLength":256}
$ (anyOf 2)object否{"additionalProperties":false}
$ (anyOf 2).startTimestring否开始时间,带时区的 ISO 8601 {"format":"date-time"}
$ (anyOf 2).detailstring | null否记录详情
$ (anyOf 2).detail (anyOf 1)string否{"maxLength":65536}
$ (anyOf 2).detail (anyOf 2)null否
$ (anyOf 2).notestring | null否备注
$ (anyOf 2).note (anyOf 1)string否{"maxLength":65536}
$ (anyOf 2).note (anyOf 2)null否
$ (anyOf 2).projectIdstring | null否项目 ID;无项目为 null
$ (anyOf 2).projectId (anyOf 1)string否{"minLength":1,"maxLength":512}
$ (anyOf 2).projectId (anyOf 2)null否
$ (anyOf 2).tagIdsarray<string>否标签 ID;GET 筛选用逗号分隔,正文用数组 {"maxItems":100}
$ (anyOf 2).tagIds[]string否{"minLength":1,"maxLength":512}
$ (anyOf 2).presetIdstring是模板 ID {"minLength":1,"maxLength":512}
$ (anyOf 2).presetEtagstring是模板的当前 ETag {"maxLength":256}
$ (anyOf 2).expectedCurrentIdstring | null否预期当前计时 ID;无计时用 null
$ (anyOf 2).expectedCurrentId (anyOf 1)string否{"minLength":1,"maxLength":512}
$ (anyOf 2).expectedCurrentId (anyOf 2)null否
$ (anyOf 2).expectedCurrentEtagstring否预期当前计时的 ETag {"maxLength":256}
完整 JSON Schema
{
  "anyOf": [
    {
      "type": "object",
      "properties": {
        "startTime": {
          "type": "string",
          "format": "date-time",
          "description": "开始时间,带时区的 ISO 8601"
        },
        "detail": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 65536
            },
            {
              "type": "null"
            }
          ],
          "description": "记录详情"
        },
        "note": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 65536
            },
            {
              "type": "null"
            }
          ],
          "description": "备注"
        },
        "projectId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            {
              "type": "null"
            }
          ],
          "description": "项目 ID;无项目为 null"
        },
        "tagIds": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512
          },
          "maxItems": 100,
          "description": "标签 ID;GET 筛选用逗号分隔,正文用数组"
        },
        "expectedCurrentId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            {
              "type": "null"
            }
          ],
          "description": "预期当前计时 ID;无计时用 null"
        },
        "expectedCurrentEtag": {
          "type": "string",
          "maxLength": 256,
          "description": "预期当前计时的 ETag"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "presetId",
        "presetEtag"
      ],
      "properties": {
        "startTime": {
          "type": "string",
          "format": "date-time",
          "description": "开始时间,带时区的 ISO 8601"
        },
        "detail": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 65536
            },
            {
              "type": "null"
            }
          ],
          "description": "记录详情"
        },
        "note": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 65536
            },
            {
              "type": "null"
            }
          ],
          "description": "备注"
        },
        "projectId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            {
              "type": "null"
            }
          ],
          "description": "项目 ID;无项目为 null"
        },
        "tagIds": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512
          },
          "maxItems": 100,
          "description": "标签 ID;GET 筛选用逗号分隔,正文用数组"
        },
        "presetId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "description": "模板 ID"
        },
        "presetEtag": {
          "type": "string",
          "maxLength": 256,
          "description": "模板的当前 ETag"
        },
        "expectedCurrentId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            {
              "type": "null"
            }
          ],
          "description": "预期当前计时 ID;无计时用 null"
        },
        "expectedCurrentEtag": {
          "type": "string",
          "maxLength": 256,
          "description": "预期当前计时的 ETag"
        }
      },
      "additionalProperties": false
    }
  ]
}

调用示例

将路径参数和请求参数替换为实际值。请求体按上述结构保存到 request.json。

curl --fail-with-body --request POST 'https://api.treering.cn/v1/time-entries/switch' \
  --header "Authorization: Bearer $TREERING_API_TOKEN" \
  --header 'Idempotency-Key: <Idempotency-Key>' \
  --header 'Content-Type: application/json' \
  --data-binary @request.json

响应

201

成功响应;具体状态取决于操作结果。

application/json

类型: object

字段类型必填说明与约束
idstring是资源、任务或操作标识
versionstring是版本号,十进制字符串,不要转为浮点数 {"pattern":"^(0|[1-9][0-9]*)$"}
etagstring是并发版本标记;保留引号用于 If-Match
updatedAtstring是服务端最后更新时间
operationIdstring否请求回执标识,无需查询状态
deletedAtstring否删除时间
startTimestring | null否开始时间,带时区的 ISO 8601
startTime (anyOf 1)string否
startTime (anyOf 2)null否
stopTimestring | null否结束时间;null 表示运行中
stopTime (anyOf 1)string否
stopTime (anyOf 2)null否
detailstring | null否记录详情
detail (anyOf 1)string否
detail (anyOf 2)null否
notestring | null否备注
note (anyOf 1)string否
note (anyOf 2)null否
projectIdstring | null否项目 ID;无项目为 null
projectId (anyOf 1)string否
projectId (anyOf 2)null否
tagIdsarray<string>否标签 ID;GET 筛选用逗号分隔,正文用数组
tagIds[]string否
sourcestring | null否来源标记
source (anyOf 1)string否
source (anyOf 2)null否
statestring否记录、任务或操作状态;语义取决于接口
durationSecondsnumber | null否持续时间,单位秒,可有小数
durationSeconds (anyOf 1)number否
durationSeconds (anyOf 2)null否
完整 JSON Schema
{
  "type": "object",
  "required": [
    "id",
    "version",
    "etag",
    "updatedAt"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "资源、任务或操作标识"
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)$",
      "description": "版本号,十进制字符串,不要转为浮点数"
    },
    "etag": {
      "type": "string",
      "description": "并发版本标记;保留引号用于 If-Match"
    },
    "updatedAt": {
      "type": "string",
      "description": "服务端最后更新时间"
    },
    "operationId": {
      "type": "string",
      "description": "请求回执标识,无需查询状态"
    },
    "deletedAt": {
      "type": "string",
      "description": "删除时间"
    },
    "startTime": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "开始时间,带时区的 ISO 8601"
    },
    "stopTime": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "结束时间;null 表示运行中"
    },
    "detail": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "记录详情"
    },
    "note": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "备注"
    },
    "projectId": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "项目 ID;无项目为 null"
    },
    "tagIds": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "标签 ID;GET 筛选用逗号分隔,正文用数组"
    },
    "source": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "来源标记"
    },
    "state": {
      "type": "string",
      "description": "记录、任务或操作状态;语义取决于接口"
    },
    "durationSeconds": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "description": "持续时间,单位秒,可有小数"
    }
  },
  "additionalProperties": false
}

400, 401, 403, 404, 409, 412, 413, 422, 428, 429, 500, 503

错误响应;请按 code 处理。

application/json

类型: object

字段类型必填说明与约束
codestring是机器可读错误码
messagestring否错误说明;请按 code 处理程序逻辑
requestIdstring否请求追踪标识
operationIdstring否请求回执标识,无需查询状态
完整 JSON Schema
{
  "type": "object",
  "required": [
    "code"
  ],
  "properties": {
    "code": {
      "type": "string",
      "description": "机器可读错误码"
    },
    "message": {
      "type": "string",
      "description": "错误说明;请按 code 处理程序逻辑"
    },
    "requestId": {
      "type": "string",
      "description": "请求追踪标识"
    },
    "operationId": {
      "type": "string",
      "description": "请求回执标识,无需查询状态"
    }
  },
  "additionalProperties": true
}

目录