Todoist技能使用说明
Todoist
通过托管的 OAuth 认证访问 Todoist API v1。管理任务、项目、分区、标签和评论。
快速开始
# 列出所有任务
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/todoist/api/v1/tasks')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
基础 URL
https://gateway.maton.ai/todoist/api/v1/{resource}
网关将请求代理到api.todoist.com/api/v1并自动注入您的 OAuth 令牌。
认证
所有请求都需要在 Authorization 头中包含 Maton API 密钥:
Authorization: Bearer $MATON_API_KEY
环境变量:将您的 API 密钥设置为MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
获取您的 API 密钥
- 登录或创建一个账户,网址是maton.ai
- 前往maton.ai/settings
- 复制您的API密钥
连接管理
请在以下地址管理您的Todoist OAuth连接https://ctrl.maton.ai。
列出连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=todoist&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
创建连接
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'todoist'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
获取连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应:
{
"connection": {
"connection_id": "21fd90f9-5935-43cd-b6c8-bde9d915ca80",
"status": "ACTIVE",
"creation_time": "2025-12-08T07:20:53.488460Z",
"last_updated_time": "2026-01-31T20:03:32.593153Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "todoist",
"metadata": {}
}
}
在浏览器中打开返回的url以完成OAuth授权。
删除连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
指定连接
如果您有多个Todoist连接,请使用Maton-Connectionheader:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/todoist/api/v1/tasks')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '21fd90f9-5935-43cd-b6c8-bde9d915ca80')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果省略,网关将使用默认(最旧的)活动连接。
API 参考
项目
列出项目
GET /todoist/api/v1/projects
响应:
{
"results": [
{
"id": "6fwFRqmVCFvWVX5R",
"name": "收件箱",
"color": "炭灰色",
"parent_id": null,
"child_order": 0,
"is_shared": false,
"is_favorite": false,
"inbox_project": true,
"view_style": "列表",
"description": "",
"is_archived": false
}
],
"next_cursor": null
}
获取项目
GET /todoist/api/v1/projects/{id}
创建项目
POST /todoist/api/v1/projects
Content-Type: application/json
{
"name": "我的项目",
"color": "蓝色",
"is_favorite": true,
"view_style": "看板"
}
参数:
- 名称(必需)- 项目名称
- parent_id- 用于嵌套的父项目ID
- 颜色- 项目颜色(例如,"红色"、"蓝色"、"绿色")
- is_favorite- 布尔值收藏状态
- 视图样式- "列表" 或 "看板"(默认值:列表)
示例:
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'name': 'My New Project', 'color': 'blue'}).encode()
req = urllib.request.Request('https://gateway.maton.ai/todoist/api/v1/projects', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
更新项目
POST /todoist/api/v1/projects/{id}
Content-Type: application/json
{
"name": "Updated Project Name",
"color": "red"
}
删除项目
DELETE /todoist/api/v1/projects/{id}
成功时返回 204 No Content。
获取项目协作者
GET /todoist/api/v1/projects/{id}/collaborators
任务
列出任务
GET /todoist/api/v1/tasks
查询参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| project_id | 字符串 | 按项目筛选 |
| section_id | 字符串 | 按部分筛选 |
| 标签 | 字符串 | 按标签名称筛选 |
| 筛选器 | 字符串 | Todoist 筛选表达式 |
| ID | 字符串 | 逗号分隔的任务 ID |
响应:
{
"results": [
{
"id": "6fwhG9wMHr4wxgpR",
"content": "购买杂货",
"description": "",
"project_id": "6fwFRqmVCFvWVX5R",
"section_id": null,
"parent_id": null,
"child_order": 1,
"priority": 2,
"checked": false,
"labels": [],
"due": {
"date": "2026-02-07T10:00:00",
"string": "明天上午10点",
"lang": "en",
"is_recurring": false
},
"added_at": "2026-02-06T20:41:08.449320Z"
}
],
"next_cursor": null
}
获取任务
GET /todoist/api/v1/tasks/{id}
创建任务
POST /todoist/api/v1/tasks
Content-Type: application/json
{
"content": "购买杂货",
"project_id": "2366834771",
"priority": 2,
"due_string": "明天上午10点",
"labels": ["购物", "差事"]
}
必填字段:
- 内容- 任务内容/标题
可选字段:
- 描述- 任务描述
- 项目ID- 要添加任务的项目(默认为收件箱)
- 分区ID- 项目内的分区
- 父任务ID- 子任务的父任务ID
- 标签- 标签名称数组
- 优先级- 1(普通)至4(紧急)
- 截止日期字符串- 自然语言截止日期("明天"、"下周一 下午3点")
- 截止日期- ISO格式 YYYY-MM-DD
- 截止日期时间- 带时区的RFC3339格式
- 负责人ID- 分配任务的用户ID
- 持续时间- 任务持续时间(整数)
- 持续时间单位- "分钟"或"天"
示例:
python <<'EOF'
import urllib.request, os, json
data = json.dumps({
'content': '完成项目报告',
'priority': 4,
'due_string': '明天下午5点',
'labels': ['工作', '紧急']
}).encode()
req = urllib.request.Request('https://gateway.maton.ai/todoist/api/v1/tasks', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
更新任务
POST /todoist/api/v1/tasks/{id}
Content-Type: application/json
{
"content": "更新后的任务内容",
"priority": 3
}
关闭任务(完成)
POST /todoist/api/v1/tasks/{id}/close
返回 204 无内容。对于重复性任务,这将安排下一次任务发生。
重新打开任务
POST /todoist/api/v1/tasks/{id}/reopen
返回 204 无内容。
删除任务
DELETE /todoist/api/v1/tasks/{id}
返回 204 无内容。
分区
列出分区
GET /todoist/api/v1/sections
GET /todoist/api/v1/sections?project_id={project_id}
响应:
{
"results": [
{
"id": "6g424m6CQm47v7mm",
"project_id": "6g424jv8X52hP7qF",
"section_order": 1,
"name": "待办事项",
"added_at": "2026-02-20T22:25:04.203675Z",
"is_archived": false,
"is_collapsed": false
}
],
"next_cursor": null
}
获取分区
GET /todoist/api/v1/sections/{id}
创建分区
POST /todoist/api/v1/sections
Content-Type: application/json
{
"name": "进行中",
"project_id": "2366834771",
"order": 2
}
必填字段:
- name- 分区名称
- project_id- 父项目ID
更新分区
POST /todoist/api/v1/sections/{id}
Content-Type: application/json
{
"name": "更新后的分区名称"
}
删除分区
DELETE /todoist/api/v1/sections/{id}
返回 204 无内容。
标签
列出标签
GET /todoist/api/v1/labels
响应:
{
"results": [
{
"id": "2182980313",
"name": "紧急",
"color": "red",
"order": 1,
"is_favorite": false
}
],
"next_cursor": null
}
获取标签
GET /todoist/api/v1/labels/{id}
创建标签
POST /todoist/api/v1/labels
Content-Type: application/json
{
"name": "工作",
"color": "blue",
"is_favorite": true
}
参数:
- name(必填)- 标签名称
- 颜色- 标签颜色
- 顺序- 排序顺序
- is_favorite- 布尔收藏状态
更新标签
POST /todoist/api/v1/labels/{id}
Content-Type: application/json
{
"name": "updated-label",
"color": "green"
}
删除标签
DELETE /todoist/api/v1/labels/{id}
返回 204 No Content。
评论
列出评论
GET /todoist/api/v1/comments?task_id={task_id}
GET /todoist/api/v1/comments?project_id={project_id}
注意:必须提供task_id或project_id中的一个。
响应:
{
"results": [
{
"id": "6g424pWVXPpwW7hR",
"item_id": "6g424pQr2xfCcFr2",
"content": "这是一条评论",
"posted_at": "2026-02-20T22:25:20.045703Z",
"posted_uid": "57402826",
"file_attachment": null,
"reactions": null
}
],
"next_cursor": null
}
获取评论
GET /todoist/api/v1/comments/{id}
创建评论
POST /todoist/api/v1/comments
Content-Type: application/json
{
"task_id": "9993408170",
"content": "别忘了检查预算"
}
必填字段:
- 内容- 评论文本
- 任务ID或项目ID- 评论的附加位置
更新评论
POST /todoist/api/v1/comments/{id}
Content-Type: application/json
{
"content": "更新后的评论文本"
}
删除评论
DELETE /todoist/api/v1/comments/{id}
返回 204 无内容。
优先级值
| 优先级 | 含义 |
|---|---|
| 1 | 普通(默认) |
| 2 | 中等 |
| 3 | 高 |
| 4 | 紧急 |
截止日期格式
每个请求使用以下格式之一:
- 截止字符串- 自然语言:"明天"、"下周一 下午3点"、"每周"
- 截止日期- 仅日期:"2026-02-15"
- due_datetime- 完整日期时间:"2026-02-15T14:00:00Z"
代码示例
JavaScript
// 创建任务
const response = await fetch('https://gateway.maton.ai/todoist/api/v1/tasks', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: 'Review pull request',
priority: 3,
due_string: 'today at 5pm'
})
});
const task = await response.json();
Python
import os
import requests
# 创建任务
response = requests.post(
'https://gateway.maton.ai/todoist/api/v1/tasks',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'},
json={
'content': 'Review pull request',
'priority': 3,
'due_string': 'today at 5pm'
}
)
task = response.json()
注意事项
- 任务ID和项目ID是字符串,不是整数
- 优先级4为最高(紧急),优先级1为正常
- 每个请求仅使用一种截止日期格式(due_string、due_date 或 due_datetime)
- 关闭重复任务会安排下一次发生
- 收件箱项目无法删除
- 重要提示:当将 curl 输出管道传输到jq或其他命令时,环境变量如$MATON_API_KEY在某些 shell 环境中可能无法正确展开
错误处理
| 状态码 | 含义 |
|---|---|
| 204 | 成功(无内容)- 适用于关闭、重新打开、删除操作 |
| 400 | 无效请求或缺少 Todoist 连接 |
| 401 | 无效或缺少Maton API密钥 |
| 404 | 资源未找到 |
| 429 | 请求频率受限 |
| 4xx/5xx | 来自Todoist API的透传错误 |
故障排除:API密钥问题
- 请检查MATON_API_KEY环境变量是否已设置:
echo $MATON_API_KEY
- 通过列出连接来验证API密钥是否有效:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
故障排除:无效的应用名称
- 请确保您的URL路径以todoist开头。例如:
- 正确:https://gateway.maton.ai/todoist/api/v1/tasks
- 错误:https://gateway.maton.ai/api/v1/tasks


微信扫一扫,打赏作者吧~