API 参考

标签与归档规则

自动或手动将发出和收到的邮件整理到文件夹中。

POST/emails/:id/labels
API 密钥

为邮件添加或移除标签

按名称或 lbl_ ID 添加和移除标签。`add` 中不存在的名称会被自动创建,除非 `create` 为 false。一封邮件最多可以带 10 个标签。

请求
curl https://sendhq.cc/api/v1/emails/id_value/labels \
  -X POST \
  -H "Authorization: Bearer $SENDHQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"add":["Billing"],"remove":["Support"]}'
200 响应
{
  "id": "em_…",
  "labels": [
    {
      "id": "lbl_…",
      "name": "Billing",
      "color": "#188038"
    }
  ]
}
GET/labels
API 密钥

列出标签及其邮件数和归档规则

列出标签及其邮件数和归档规则

请求
curl https://sendhq.cc/api/v1/labels \
  -X GET \
  -H "Authorization: Bearer $SENDHQ_API_KEY"
200 响应
{
  "data": [],
  "count": 0,
  "mailbox": {
    "inboxUnread": 0,
    "updatesUnread": 0,
    "spamTotal": 0,
    "importantUnread": 0,
    "resortPending": 0
  }
}
POST/labels
API 密钥

创建标签,可同时设置自动归档规则

创建一个文件夹式的标签。设置 `skip_inbox: true` 可将其变为分类:收到的邮件如果获得了该标签(无论是通过规则、作为带该标签发出的会话的回复,还是手动添加),都会被归档,因此只会出现在该标签中,永远不会出现在收件箱里。可选的 `rules` 会自动归档新发出或新收到的邮件:规则上设置的每个条件都必须匹配(inbox_id、direction,以及不区分大小写的 from/to/subject 子串)。设置 `apply_to_existing` 还会归档已保留的邮件。

请求
curl https://sendhq.cc/api/v1/labels \
  -X POST \
  -H "Authorization: Bearer $SENDHQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Agent/Orders","color":"#188038","skip_inbox":true,"rules":[{"inbox_id":"inb_…"}],"apply_to_existing":true}'
201 响应
{
  "id": "lbl_…",
  "name": "Agent/Orders",
  "color": "#188038",
  "skipInbox": true,
  "totalCount": 0,
  "unreadCount": 0,
  "rules": []
}
GET/labels/:id
API 密钥

按 ID 或名称获取标签

按 ID 或名称获取标签

请求
curl https://sendhq.cc/api/v1/labels/id_value \
  -X GET \
  -H "Authorization: Bearer $SENDHQ_API_KEY"
200 响应
{
  "id": "lbl_…",
  "name": "Billing",
  "color": "#188038",
  "skipInbox": false,
  "totalCount": 0,
  "unreadCount": 0,
  "rules": []
}
PATCH/labels/:id
API 密钥

重命名标签、更改颜色或将其变为分类

更改 `name`、`color` 或 `skip_inbox`。开启 `skip_inbox` 时,还会归档标签中已有的收到的邮件,除非 `apply_to_existing` 为 false。

请求
curl https://sendhq.cc/api/v1/labels/id_value \
  -X PATCH \
  -H "Authorization: Bearer $SENDHQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Finance/Billing","color":"#1a73e8","skip_inbox":true}'
200 响应
{
  "id": "lbl_…",
  "name": "Finance/Billing",
  "color": "#1a73e8",
  "skipInbox": true
}
DELETE/labels/:id
API 密钥

删除标签,但不删除其中的邮件

删除标签,但不删除其中的邮件

请求
curl https://sendhq.cc/api/v1/labels/id_value \
  -X DELETE \
  -H "Authorization: Bearer $SENDHQ_API_KEY"
200 响应
{
  "ok": true
}
POST/labels/:id/rules
API 密钥

为标签添加自动归档规则

为标签添加自动归档规则

请求
curl https://sendhq.cc/api/v1/labels/id_value/rules \
  -X POST \
  -H "Authorization: Bearer $SENDHQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"direction":"in","from":"@stripe.com","subject":"invoice","skip_inbox":true,"apply_to_existing":false}'
201 响应
{
  "id": "lrule_…",
  "labelId": "lbl_…",
  "direction": "in",
  "inboxId": null,
  "from": "@stripe.com",
  "to": null,
  "subject": "invoice",
  "skipInbox": true
}
DELETE/labels/:id/rules/:rule_id
API 密钥

删除自动归档规则

删除自动归档规则

请求
curl https://sendhq.cc/api/v1/labels/id_value/rules/rule_id_value \
  -X DELETE \
  -H "Authorization: Bearer $SENDHQ_API_KEY"
200 响应
{
  "ok": true
}