Skip to content

使用笔记 ​

格式 ​

正文为 Markdown(content_markdown)。使用 ?format=json 获取 TipTap JSON,或用 ?format=both 同时获取两者。写入时请在 content_markdown 和 content_json 中只发送一个。

代码模式的笔记("mode": "code")使用 files 数组代替正文。

分页与搜索 ​

GET /notes 按最新优先排序,并使用游标分页:

bash
curl "https://notes-api.palmcode.cl/api/v1/notes?limit=25&q=invoice&tag=work" \
  -H "Authorization: Bearer $PALMNOTES_TOKEN"
# → { "data": [...], "meta": { "next_cursor": "…" } }
curl "https://notes-api.palmcode.cl/api/v1/notes?limit=25&cursor=<next_cursor>" \
  -H "Authorization: Bearer $PALMNOTES_TOKEN"
ts
let cursor: string | null = null;
do {
  const url = new URL('https://notes-api.palmcode.cl/api/v1/notes');
  url.searchParams.set('limit', '25');
  if (cursor) url.searchParams.set('cursor', cursor);
  const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.PALMNOTES_TOKEN}` } });
  const { data, meta } = await res.json();
  for (const note of data) console.log(note.title);
  cursor = meta.next_cursor;
} while (cursor);
python
import os, requests

headers = {"Authorization": f"Bearer {os.environ['PALMNOTES_TOKEN']}"}
params = {"limit": 25}
while True:
    body = requests.get("https://notes-api.palmcode.cl/api/v1/notes", params=params, headers=headers).json()
    for note in body["data"]:
        print(note["title"])
    cursor = body["meta"]["next_cursor"]
    if not cursor:
        break
    params["cursor"] = cursor

最后一页的 next_cursor 为 null。列表只返回简短的 excerpt;添加 include=content 可获取完整正文。

避免更新丢失 ​

每条笔记都有一个不透明的 version。更新时将其放入 If-Match 发回;如果值已过期,将返回 409 version_conflict。

bash
curl -X PATCH https://notes-api.palmcode.cl/api/v1/notes/$ID \
  -H "Authorization: Bearer $PALMNOTES_TOKEN" \
  -H "If-Match: $VERSION" \
  -H "Content-Type: application/json" \
  -d '{"title":"New title"}'
ts
const res = await fetch(`https://notes-api.palmcode.cl/api/v1/notes/${id}`, {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${process.env.PALMNOTES_TOKEN}`,
    'If-Match': version, // the `version` you last read
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ title: 'New title' }),
});
if (res.status === 409) {
  // version_conflict: re-read the note, merge, retry
}
python
import os, requests

r = requests.patch(
    f"https://notes-api.palmcode.cl/api/v1/notes/{note_id}",
    headers={
        "Authorization": f"Bearer {os.environ['PALMNOTES_TOKEN']}",
        "If-Match": version,  # the `version` you last read
    },
    json={"title": "New title"},
)
if r.status_code == 409:
    pass  # version_conflict: re-read the note, merge, retry

删除与历史记录 ​

DELETE /notes/{id} 会将笔记移入回收站;添加 ?permanent=true 可永久删除。每条普通笔记会保留最近 10 个版本;可通过 /notes/{id}/versions 列出,并用 POST …/versions/{vid}/restore 恢复(会先保存当前状态,因此恢复是可撤销的)。