# GeekTask API — guide for scripts and AI assistants

GeekTask (https://geektools.net/task) is a to-do list and habit tracker. This
page tells a script or an AI assistant how to read and change one user's tasks
with a **personal API key**.

The user creates a key in GeekTask (account menu → **API keys**) and gives it
to you. It looks like `gtk_` followed by 43 letters, digits, `-` or `_`.
Treat it like a password: never print it, never put it in a URL, never store
it in a file that is shared or committed.

## Basics

- Base URL: `https://geektools.net/api`
- Every request: header `Authorization: Bearer <key>`
- Request and response bodies are JSON (`Content-Type: application/json`),
  except file uploads (multipart) and file downloads (raw bytes).
- Dates are `YYYY-MM-DD`. "Today" is the date in **Asia/Singapore (UTC+8)**.
- Instants (`createdAt`, `updatedAt`, `completedAt`, `reminderAt`) are
  **epoch milliseconds** (UTC).
- Errors return JSON: `{"status": 400, "error": "...", "message": "...", "path": "..."}`.
  Show `message` to the user — it says what went wrong. Validation errors
  also carry `fields`: `[{"field": "text", "message": "must not be blank"}]`.

In shell examples below, the key is in an environment variable:

```bash
export GEEKTASK_API_KEY='gtk_...'      # set once; don't echo it
```

## What a key can do

| Method | Path | What it does |
|---|---|---|
| GET | `/tasks` | List all tasks |
| POST | `/tasks` | Create a task |
| PUT | `/tasks/{id}` | Edit a task |
| PATCH | `/tasks/{id}/check` | Set progress (complete / uncomplete) |
| POST | `/tasks/{id}/postpone` | Set a one-time task's due date to tomorrow (today + 1) |
| POST | `/tasks/{id}/pickup` | Bring a postponed task back to today |
| DELETE | `/tasks/{id}` | Delete a task (and its files) |
| PUT | `/tasks/order` | Reorder tasks |
| POST | `/tasks/{id}/attachments` | Upload one file |
| GET | `/tasks/{id}/attachments/{attachmentId}` | Download a file |
| DELETE | `/tasks/{id}/attachments/{attachmentId}` | Remove a file |
| GET | `/sync/version` | Change counter (cheap "did anything change?") |
| GET | `/streak` | The user's streak (read-only) |

Anything else (account, password, devices, API-key management) needs the user
to be signed in on the website; a key gets `403`.

## Rules (read these)

1. **Limit: 120 requests per minute per key.** Over the limit you get `429`
   with a `Retry-After` header (seconds). Wait that long, then continue.
   Don't poll in a tight loop; use `GET /sync/version` to detect changes.
2. **No code-injection-shaped text.** Task text, descriptions and file names
   that look like web or database attacks (HTML `<script>` tags, `onerror=`
   style handlers, `javascript:` links, `'; DROP TABLE`, `UNION SELECT`,
   `{{7*7}}` / `${...}` templates, etc.) are rejected with `400`, and **the
   key that sent them is revoked at once**. Describe such things in plain
   words instead (e.g. "remove the script tag from the footer").
3. Before deleting tasks or files, **confirm with the user** unless they
   clearly asked for that exact deletion. Deletes can't be undone.
4. `401` means the key is wrong, expired or revoked (or the user changed
   their password). Ask the user for a new key; don't retry.

## The task object

```json
{
  "id": 512,
  "text": "Prepare Q4 report",
  "description": "Numbers from finance, charts attached.",
  "type": "once",
  "createdDate": "2026-11-16",
  "dueDate": "2026-11-17",
  "targetCount": 1,
  "checkedCount": 0,
  "completedDate": null,
  "completedAt": null,
  "reminderAt": 1795420800000,
  "sortOrder": -3,
  "updatedAt": 1795333200000,
  "attachments": [
    {"id": 41, "filename": "chart.png", "contentType": "image/png", "size": 662312, "createdAt": 1795333300000}
  ]
}
```

- `text`: title, 1–120 characters. `description`: optional notes, up to 2000.
- `type`: `"once"` (a one-time task with a `dueDate`) or `"repeat"` (a habit
  with a `repeat` rule).
- `repeat` (repeat tasks only):
  `{"kind": "daily"}`,
  `{"kind": "weekly", "weekdays": [1, 3, 5]}` (0 = Sunday … 6 = Saturday), or
  `{"kind": "monthly", "monthDay": 15}`.
- `targetCount` 1–9: how many checks finish the task (e.g. "drink water ×8").
  `checkedCount` is the progress.
- One-time task is **done** when `completedDate` is set
  (`checkedCount == targetCount`). It is **overdue** when not done and
  `dueDate` is before today.
- Repeat task is **done today** when `lastCheckedDate` is today and
  `checkedCount == targetCount`. Progress from an earlier day doesn't count
  for today; it resets when the user next checks it.
- `lastCheckedDate` (repeat tasks): the last day it was checked.
- Fields that are null may be missing from the JSON.

A repeat task (habit) looks like this:

```json
{
  "id": 513, "text": "Gym", "type": "repeat", "createdDate": "2026-11-10",
  "repeat": {"kind": "weekly", "weekdays": [1, 3, 5]},
  "targetCount": 2, "checkedCount": 2, "lastCheckedDate": "2026-11-16",
  "sortOrder": -4, "updatedAt": 1795330000000, "attachments": []
}
```

New tasks go to the top of the list (lowest `sortOrder`).

## Examples

List tasks:

```bash
curl -s https://geektools.net/api/tasks -H "Authorization: Bearer $GEEKTASK_API_KEY"
```

Create a one-time task (due today if `dueDate` is left out; can't be in the past):

```bash
curl -s -X POST https://geektools.net/api/tasks \
  -H "Authorization: Bearer $GEEKTASK_API_KEY" -H 'Content-Type: application/json' \
  -d '{"text":"Call the dentist","type":"once","dueDate":"2026-11-20","description":"Ask about the cleaning"}'
```

Create a habit (Mon/Wed/Fri, 2 checks each day):

```bash
curl -s -X POST https://geektools.net/api/tasks \
  -H "Authorization: Bearer $GEEKTASK_API_KEY" -H 'Content-Type: application/json' \
  -d '{"text":"Gym","type":"repeat","repeat":{"kind":"weekly","weekdays":[1,3,5]},"targetCount":2}'
```

Create with a reminder (epoch ms; e.g. 2026-11-20 09:00 Singapore time). To
get the number for a local time:
`python3 -c "import datetime as d; print(int(d.datetime(2026,11,20,9,0,tzinfo=d.timezone(d.timedelta(hours=8))).timestamp()*1000))"`
(or `date -d '2026-11-20 09:00 +08:00' +%s000` on Linux).

```bash
curl -s -X POST https://geektools.net/api/tasks \
  -H "Authorization: Bearer $GEEKTASK_API_KEY" -H 'Content-Type: application/json' \
  -d '{"text":"Submit expenses","type":"once","dueDate":"2026-11-20","reminderAt":1795136400000}'
```

Edit a task — `text` is **required** on every edit (send the current text if
you're not changing it). Other fields: left out or `null` = unchanged;
`"description": ""` clears the description; `"reminderAt": 0` clears the
reminder. `dueDate` applies to one-time tasks, `repeat` to repeat tasks:

```bash
curl -s -X PUT https://geektools.net/api/tasks/512 \
  -H "Authorization: Bearer $GEEKTASK_API_KEY" -H 'Content-Type: application/json' \
  -d '{"text":"Prepare Q4 report (draft)","dueDate":"2026-11-18"}'
```

Complete a task (set `checkedCount` to its `targetCount`; `0` un-completes):

```bash
curl -s -X PATCH https://geektools.net/api/tasks/512/check \
  -H "Authorization: Bearer $GEEKTASK_API_KEY" -H 'Content-Type: application/json' \
  -d '{"checkedCount":1}'
```

Postpone sets the due date to **tomorrow** (today + 1), even if the task was
due later — to move it to another day, edit `dueDate` instead. Pickup brings a
postponed task back (to today, or to its original date if it was overdue):

```bash
curl -s -X POST https://geektools.net/api/tasks/512/postpone -H "Authorization: Bearer $GEEKTASK_API_KEY"
curl -s -X POST https://geektools.net/api/tasks/512/pickup   -H "Authorization: Bearer $GEEKTASK_API_KEY"
```

Delete a task (returns `204`; its files are deleted too):

```bash
curl -s -X DELETE https://geektools.net/api/tasks/512 -H "Authorization: Bearer $GEEKTASK_API_KEY"
```

Reorder (ids in the new top-to-bottom order; all ids must be the user's; returns `204`):

```bash
curl -s -X PUT https://geektools.net/api/tasks/order \
  -H "Authorization: Bearer $GEEKTASK_API_KEY" -H 'Content-Type: application/json' \
  -d '{"ids":[514,512,513]}'
```

## Attachments

- Up to **20 MB in total per task** and **20 files per task**; one file per
  upload request (form field `file`). The account also has a storage quota.
- Upload returns `201` with the updated task (see its `attachments`):

```bash
curl -s -X POST https://geektools.net/api/tasks/512/attachments \
  -H "Authorization: Bearer $GEEKTASK_API_KEY" \
  -F "file=@./report.pdf;type=application/pdf"
```

- Download (raw bytes; save to a file):

```bash
curl -s -o report.pdf https://geektools.net/api/tasks/512/attachments/41 \
  -H "Authorization: Bearer $GEEKTASK_API_KEY"
```

- Remove a file (returns the updated task):

```bash
curl -s -X DELETE https://geektools.net/api/tasks/512/attachments/41 \
  -H "Authorization: Bearer $GEEKTASK_API_KEY"
```

## Detecting changes

`GET /sync/version` returns `{"version": 1234}`. The number goes up whenever
any task or file changes (from any device). Re-fetch `GET /tasks` only when
it changed.

## Windows PowerShell

`curl` in PowerShell 5 is an alias; use `curl.exe`, or:

```powershell
$h = @{ Authorization = "Bearer $env:GEEKTASK_API_KEY" }
Invoke-RestMethod https://geektools.net/api/tasks -Headers $h
Invoke-RestMethod https://geektools.net/api/tasks -Method Post -Headers $h `
  -ContentType 'application/json' -Body (@{ text = 'Call the dentist'; type = 'once' } | ConvertTo-Json)
```
