时间记录

搜索时间记录

POST /v1/time-entries/search

默认每页 100 条,最多 500 条。保留筛选条件并传入 nextCursor 继续读取;分页过程中数据可能变化,完整备份请使用导出。

请求体

必填

application/json

类型: object

字段类型必填说明与约束
fromDatestring否筛选开始日(含) {"format":"date"}
toDateExclusivestring否筛选结束日(不含) {"format":"date"}
fromstring否开始时间(含);与 to 同时提供 {"format":"date-time"}
tostring否结束时间(不含);与 from 同时提供 {"format":"date-time"}
statestring否记录、任务或操作状态;语义取决于接口 {"enum":["running","stopped","invalid"]}
projectIdsarray<string>否项目 ID 筛选;GET 用逗号分隔,POST 用数组 {"minItems":1,"maxItems":100}
projectIds[]string否{"minLength":1,"maxLength":512}
tagIdsarray<string>否标签 ID;GET 筛选用逗号分隔,正文用数组 {"minItems":1,"maxItems":100}
tagIds[]string否{"minLength":1,"maxLength":512}
tagMatchstring否标签匹配:any 或 all {"enum":["any","all"]}
noProjectboolean否仅匹配无项目的记录
noTagsboolean否仅匹配无标签的记录
includeDescendantsboolean否筛选时包含后代标签
archivedstring否归档筛选:active、only 或 all {"enum":["active","only","all"]}
matchstring否时间匹配:overlaps 或 startsWithin {"enum":["overlaps","startsWithin"]}
textstring否搜索文本;使用 POST 避免进入 URL {"maxLength":500}
limitinteger否每页数量,默认 100,最多 500 {"minimum":1,"maximum":500}
cursorstring否不透明游标;原样传回,不要解析 {"maxLength":8192}
完整 JSON Schema
{
  "type": "object",
  "properties": {
    "fromDate": {
      "type": "string",
      "format": "date",
      "description": "筛选开始日(含)"
    },
    "toDateExclusive": {
      "type": "string",
      "format": "date",
      "description": "筛选结束日(不含)"
    },
    "from": {
      "type": "string",
      "format": "date-time",
      "description": "开始时间(含);与 to 同时提供"
    },
    "to": {
      "type": "string",
      "format": "date-time",
      "description": "结束时间(不含);与 from 同时提供"
    },
    "state": {
      "type": "string",
      "enum": [
        "running",
        "stopped",
        "invalid"
      ],
      "description": "记录、任务或操作状态;语义取决于接口"
    },
    "projectIds": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 512
      },
      "minItems": 1,
      "maxItems": 100,
      "description": "项目 ID 筛选;GET 用逗号分隔,POST 用数组"
    },
    "tagIds": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 512
      },
      "minItems": 1,
      "maxItems": 100,
      "description": "标签 ID;GET 筛选用逗号分隔,正文用数组"
    },
    "tagMatch": {
      "type": "string",
      "enum": [
        "any",
        "all"
      ],
      "description": "标签匹配:any 或 all"
    },
    "noProject": {
      "type": "boolean",
      "description": "仅匹配无项目的记录"
    },
    "noTags": {
      "type": "boolean",
      "description": "仅匹配无标签的记录"
    },
    "includeDescendants": {
      "type": "boolean",
      "description": "筛选时包含后代标签"
    },
    "archived": {
      "type": "string",
      "enum": [
        "active",
        "only",
        "all"
      ],
      "description": "归档筛选:active、only 或 all"
    },
    "match": {
      "type": "string",
      "enum": [
        "overlaps",
        "startsWithin"
      ],
      "description": "时间匹配:overlaps 或 startsWithin"
    },
    "text": {
      "type": "string",
      "maxLength": 500,
      "description": "搜索文本;使用 POST 避免进入 URL"
    },
    "limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 500,
      "description": "每页数量,默认 100,最多 500"
    },
    "cursor": {
      "type": "string",
      "maxLength": 8192,
      "description": "不透明游标;原样传回,不要解析"
    }
  },
  "additionalProperties": false
}

调用示例

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

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

响应

200

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

application/json

类型: object

字段类型必填说明与约束
itemsarray<object>是资源、事件或操作结果列表
items[]object否{"additionalProperties":false}
items[].idstring是资源、任务或操作标识
items[].versionstring是版本号,十进制字符串,不要转为浮点数 {"pattern":"^(0|[1-9][0-9]*)$"}
items[].etagstring是并发版本标记;保留引号用于 If-Match
items[].updatedAtstring是服务端最后更新时间
items[].operationIdstring否请求回执标识,无需查询状态
items[].deletedAtstring否删除时间
items[].startTimestring | null否开始时间,带时区的 ISO 8601
items[].startTime (anyOf 1)string否
items[].startTime (anyOf 2)null否
items[].stopTimestring | null否结束时间;null 表示运行中
items[].stopTime (anyOf 1)string否
items[].stopTime (anyOf 2)null否
items[].detailstring | null否记录详情
items[].detail (anyOf 1)string否
items[].detail (anyOf 2)null否
items[].notestring | null否备注
items[].note (anyOf 1)string否
items[].note (anyOf 2)null否
items[].projectIdstring | null否项目 ID;无项目为 null
items[].projectId (anyOf 1)string否
items[].projectId (anyOf 2)null否
items[].tagIdsarray<string>否标签 ID;GET 筛选用逗号分隔,正文用数组
items[].tagIds[]string否
items[].sourcestring | null否来源标记
items[].source (anyOf 1)string否
items[].source (anyOf 2)null否
items[].statestring否记录、任务或操作状态;语义取决于接口
items[].durationSecondsnumber | null否持续时间,单位秒,可有小数
items[].durationSeconds (anyOf 1)number否
items[].durationSeconds (anyOf 2)null否
hasMoreboolean是是否还有下一页
nextCursorstring | null是下一页游标;末页为 null
nextCursor (anyOf 1)string否
nextCursor (anyOf 2)null否
evaluatedAtstring是服务端计算结果的时间
effectiveRangeobject | null是此次查询固定的时间范围
effectiveRange (anyOf 1)object否
effectiveRange (anyOf 1).fromstring是开始时间(含);与 to 同时提供
effectiveRange (anyOf 1).tostring是结束时间(不含);与 from 同时提供
effectiveRange (anyOf 2)null否
完整 JSON Schema
{
  "type": "object",
  "required": [
    "items",
    "hasMore",
    "nextCursor",
    "evaluatedAt",
    "effectiveRange"
  ],
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "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
      },
      "description": "资源、事件或操作结果列表"
    },
    "hasMore": {
      "type": "boolean",
      "description": "是否还有下一页"
    },
    "nextCursor": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "下一页游标;末页为 null"
    },
    "evaluatedAt": {
      "type": "string",
      "description": "服务端计算结果的时间"
    },
    "effectiveRange": {
      "anyOf": [
        {
          "type": "object",
          "required": [
            "from",
            "to"
          ],
          "properties": {
            "from": {
              "type": "string",
              "description": "开始时间(含);与 to 同时提供"
            },
            "to": {
              "type": "string",
              "description": "结束时间(不含);与 from 同时提供"
            }
          }
        },
        {
          "type": "null"
        }
      ],
      "description": "此次查询固定的时间范围"
    }
  }
}

400, 401, 403, 404, 413, 422, 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
}

目录