API Docs

OpenAPI JSON

For your own scripts, shortcuts and AI tools. Requests access only the authenticated account's data.

Quick start

Before your first request, generate and configure a token as described in Authentication.

Base URL: https://api.treering.cn/v1. Save the token in TREERING_API_TOKEN and read time entries:

curl --fail-with-body 'https://api.treering.cn/v1/time-entries?limit=5' \
  --header "Authorization: Bearer $TREERING_API_TOKEN"

Most workflows use time entries, timers, projects, tags, reports and exports. Presets and time points support the corresponding Treering features.

Create and retry

To create a project, supply a name and a new UUID as Idempotency-Key:

curl --fail-with-body 'https://api.treering.cn/v1/projects' \
  --header "Authorization: Bearer $TREERING_API_TOKEN" \
  --header 'Content-Type: application/json' \
  --header "Idempotency-Key: $(uuidgen)" \
  --data '{"name":"Personal project"}'

This example is for a first attempt. To retry, save the UUID beforehand and reuse the same UUID, body and etag. Do not regenerate it on each retry. Results are retained for 30 days. After that, reconcile the outcome before submitting again; an old UUID may execute again. Legacy timestamp:UUID keys remain accepted.

Update and delete

Read the object first. Copy its etag into the If-Match header, including quotes, then submit the change with an idempotency key.

A 412 response means another device changed the object: read it again and reconcile before submitting. A 428 response means If-Match is missing. This prevents a script from overwriting newer changes made on your phone.

A 200 response to deleting a project or tag means deletion and all server-side relationship updates have completed. No status polling is needed. Deleting a project sets projectId to null on related time entries and presets. Deleting a tag removes it from tagIds and sets parentId to null on direct child tags. Time entries, presets and child tags are retained. Versions, query indexes and sync changes commit together; processing failures roll back all changes. After a network timeout, retry the original request with the same Idempotency-Key. Other devices receive updates during subsequent sync.

Timers

Read current for the active timer. Start requires no running timer; it returns a conflict instead of stopping one automatically. To use a preset, pass presetId and presetEtag in the same start request; no separate endpoint is needed. Stop uses the current entry's id and etag. Use switch only when an atomic transition is required; provide the current timer's id and etag so a newly started timer is not stopped accidentally.

Queries and pagination

Use ISO 8601 timestamps with time zones. Supply from and to together for [from,to). Time entries default to the last 30 days with overlap matching. Pages default to 100 items, maximum 500.

Pass nextCursor as cursor with unchanged query parameters until hasMore=false. Treat cursors as opaque. Ordinary pagination is not a backup. Projects, tags and presets default to non-archived items.

For text search, use POST /time-entries/search to keep search text out of URL logs. Filter arrays use comma-separated values in GET and JSON arrays in POST.

Reports

Supply from, to and timeZone, such as Asia/Shanghai. Defaults are daily buckets and no grouping; set period and groupBy when needed. The maximum range is 366 days. Running timers are excluded by default. Durations are seconds. Tag groups may overlap and must not be added together.

Full export

  1. POST /exports with {}, authentication and an idempotency key; keep the job id.
  2. GET /exports/{id}; follow Retry-After until state=ready. Inspect errorCode on failed.
  3. GET /exports/{id}/download with authentication.

Exports contain only data uploaded to the server. Files last 7 days and can be regenerated. File retention is separate from permanent export access. Verify bytes and sha256 after downloading.

Errors and limits

Branch on code, not the English message. 401 means an invalid token; 403 means missing entitlement or permission; 404 means unavailable or not owned; 409 means a state conflict. Retry 429/503 according to Retry-After.

Ordinary requests allow 120 per account and 60 per token per minute; reports allow 10/5. Request bodies are limited to 1 MiB and list responses to 4 MiB. Detail/note each allow 64 KiB; names allow 300 characters. One export may be building per account; successful exports have a 10-minute regeneration cooldown.

This documentation does not send live requests.

Deletion and re-creation

Deleted records disappear from ordinary lists. Reading or editing their original ID returns 404. The server keeps internal deletion markers for device synchronization; these are not exposed as API endpoints.

The API does not undo deletion. If you saved a record body, submit it to the existing create endpoint to receive a new ID. This does not restore the original ID, relationships or historical order. Export first when you need a lasting copy. To temporarily hide a project, tag or preset, PATCH archiveTime instead; set it to null later to unarchive.

Exports include the five uploaded resource types, ordering data, deletion markers and a manifest. They contain no tokens and are not the legacy client backup format. File sizes and versions are decimal strings.

On this page