Kit技能使用说明
Kit
通过托管的OAuth认证访问Kit(前身为ConvertKit)API。管理订阅者、标签、表单、序列、广播、自定义字段和Webhook。
快速开始
# List subscribers
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/kit/v4/subscribers?per_page=10')
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/kit/{native-api-path}
将{native-api-path}替换为实际的Kit API端点路径。网关将请求代理至api.kit.com并自动注入您的OAuth令牌。
认证
所有请求都需要在Authorization头部中包含Maton API密钥:
Authorization: Bearer $MATON_API_KEY
环境变量:将您的API密钥设置为MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
获取您的API密钥
复制您的API密钥
在https://ctrl.maton.ai管理您的 Kit OAuth 连接。
列出连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=kit&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': 'kit'}).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": "cb2025b3-706f-4b5d-87a5-c6809c0c7ec4",
"status": "ACTIVE",
"creation_time": "2026-02-07T00:04:08.476727Z",
"last_updated_time": "2026-02-07T00:05:58.001964Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "kit",
"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
指定连接
如果您有多个 Kit 连接,请使用Maton-Connection标头指定要使用哪一个:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/kit/v4/subscribers')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', 'cb2025b3-706f-4b5d-87a5-c6809c0c7ec4')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果省略,网关将使用默认(最早创建的)活动连接。
API 参考
订阅者
列出订阅者
GET /kit/v4/subscribers
查询参数:
- per_page- 每页结果数(默认:500,最大:1000)
- after- 下一页游标
- 之前- 上一页游标
- 状态- 筛选条件:活跃、非活跃、退信、投诉、已取消或全部
- 电子邮件地址- 按特定电子邮件筛选
- 创建时间之后/创建时间之前- 按创建日期筛选(年-月-日)
- 更新时间之后/更新时间之前- 按更新日期筛选(年-月-日)
- 包含总计数- 包含总计数(较慢)
响应:
{
"subscribers": [
{
"id": 3914682852,
"first_name": "Test User",
"email_address": "test@example.com",
"state": "active",
"created_at": "2026-02-07T00:42:54Z",
"fields": {"company": null}
}
],
"pagination": {
"has_previous_page": false,
"has_next_page": false,
"start_cursor": "WzE0OV0=",
"end_cursor": "WzE0OV0=",
"per_page": 500
}
}
获取订阅者
GET /kit/v4/subscribers/{id}
创建订阅者
POST /kit/v4/subscribers
Content-Type: application/json
{
"email_address": "user@example.com",
"first_name": "John"
}
更新订阅者
PUT /kit/v4/subscribers/{id}
Content-Type: application/json
{
"first_name": "Updated Name"
}
标签
列出标签
GET /kit/v4/tags
查询参数:每页数量,之后,之前,包含总计数
创建标签
POST /kit/v4/tags
Content-Type: application/json
{
"name": "new-tag"
}
响应:
{
"tag": {
"id": 15690016,
"name": "new-tag",
"created_at": "2026-02-07T00:42:53Z"
}
}
更新标签
PUT /kit/v4/tags/{id}
Content-Type: application/json
{
"name": "updated-tag-name"
}
删除标签
DELETE /kit/v4/tags/{id}
成功时返回204 No Content。
为订阅者添加标签
POST /kit/v4/tags/{tag_id}/subscribers
Content-Type: application/json
{
"email_address": "user@example.com"
}
从订阅者移除标签
DELETE /kit/v4/tags/{tag_id}/subscribers/{subscriber_id}
成功时返回204 No Content。
列出带标签的订阅者
GET /kit/v4/tags/{tag_id}/subscribers
表单
列出表单
GET /kit/v4/forms
查询参数:
- 每页数量,之后,之前,包含总数
- 状态- 按以下条件筛选:激活,归档,已删除,或全部
- 类型-嵌入用于嵌入式表单,托管用于落地页
响应:
{
"forms": [
{
"id": 9061198,
"name": "Creator Profile",
"created_at": "2026-02-07T00:00:32Z",
"type": "embed",
"format": null,
"embed_js": "https://chris-kim-2.kit.com/c682763b07/index.js",
"embed_url": "https://chris-kim-2.kit.com/c682763b07",
"archived": false,
"uid": "c682763b07"
}
],
"pagination": {...}
}
将订阅者添加到表单
POST /kit/v4/forms/{form_id}/subscribers
Content-Type: application/json
{
"email_address": "user@example.com"
}
列出表单订阅者
GET /kit/v4/forms/{form_id}/subscribers
序列
列出序列
GET /kit/v4/sequences
响应:
{
"sequences": [
{
"id": 123,
"name": "Welcome Sequence",
"hold": false,
"repeat": false,
"created_at": "2026-01-01T00:00:00Z"
}
],
"pagination": {...}
}
将订阅者添加到序列
POST /kit/v4/sequences/{sequence_id}/subscribers
Content-Type: application/json
{
"email_address": "user@example.com"
}
列出序列订阅者
GET /kit/v4/sequences/{sequence_id}/subscribers
广播
列出广播
GET /kit/v4/broadcasts
查询参数:每页数量,之后,之前,包含总计数
响应:
{
"broadcasts": [
{
"id": 123,
"publication_id": 456,
"created_at": "2026-02-07T00:00:00Z",
"subject": "My Broadcast",
"preview_text": "Preview...",
"content": "<p>Content</p>",
"public": false,
"published_at": null,
"send_at": null,
"email_template": {"id": 123, "name": "Text only"}
}
],
"pagination": {...}
}
细分
列出细分
GET /kit/v4/segments
查询参数:每页数量,之后,之前,包含总计数
自定义字段
列出自定义字段
GET /kit/v4/custom_fields
响应:
{
"custom_fields": [
{
"id": 1192946,
"name": "ck_field_1192946_company",
"key": "company",
"label": "Company"
}
],
"pagination": {...}
}
创建自定义字段
POST /kit/v4/custom_fields
Content-Type: application/json
{
"label": "Company"
}
更新自定义字段
PUT /kit/v4/custom_fields/{id}
Content-Type: application/json
{
"label": "Company Name"
}
删除自定义字段
DELETE /kit/v4/custom_fields/{id}
成功时返回204 No Content。
购买记录
列出购买记录
GET /kit/v4/purchases
查询参数:每页数量、之后、之前、包含总计数
电子邮件模板
列出电子邮件模板
GET /kit/v4/email_templates
响应:
{
"email_templates": [
{
"id": 4956167,
"name": "Text only",
"is_default": true,
"category": "Classic"
}
],
"pagination": {...}
}
Webhooks
列出Webhooks
GET /kit/v4/webhooks
创建Webhook
POST /kit/v4/webhooks
Content-Type: application/json
{
"target_url": "https://example.com/webhook",
"event": {"name": "subscriber.subscriber_activate"}
}
响应:
{
"webhook": {
"id": 5291560,
"account_id": 2596262,
"event": {
"name": "subscriber_activate",
"initiator_value": null
},
"target_url": "https://example.com/webhook"
}
}
删除Webhook
DELETE /kit/v4/webhooks/{id}
成功时返回204 No Content。
分页
Kit 使用基于游标的分页。请使用after和before查询参数,并配合响应中返回的游标值。
GET /kit/v4/subscribers?per_page=100&after=WzE0OV0=
响应中包含分页信息:
{
"subscribers": [...],
"pagination": {
"has_previous_page": false,
"has_next_page": true,
"start_cursor": "WzE0OV0=",
"end_cursor": "WzI0OV0=",
"per_page": 100
}
}
代码示例
JavaScript
const response = await fetch(
'https://gateway.maton.ai/kit/v4/subscribers?per_page=10',
{
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
}
}
);
const data = await response.json();
Python
import os
import requests
response = requests.get(
'https://gateway.maton.ai/kit/v4/subscribers',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'},
params={'per_page': 10}
)
data = response.json()
注意事项
- Kit API 使用 V4 版本(V3 已弃用)
- 订阅者 ID 为整数
- 自定义字段键名由标签自动生成
- 批量操作(>100 项)将异步处理
- 删除操作返回 204 No Content 且响应体为空
- 重要提示:使用 curl 命令时,若 URL 包含方括号,请使用curl -g以禁用全局解析
- 重要提示:将 curl 输出通过管道传递给jq或其他命令时,环境变量如$MATON_API_KEY在某些shell环境中可能无法正确展开
错误处理
| 状态码 | 含义 |
|---|---|
| 400 | 缺少Kit连接 |
| 401 | Maton API密钥无效或缺失 |
| 403 | 权限不足(请检查OAuth范围) |
| 404 | 资源未找到 |
| 429 | 请求频率受限 |
| 4xx/5xx | 来自Kit 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路径以套件例如:
- 正确:https://gateway.maton.ai/kit/v4/subscribers
- 错误:https://gateway.maton.ai/v4/subscribers


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