跳转到主要内容
我们推荐直接在 AI 对话中构建自动化示例。只需描述你想要的工作流,AI 会为你完成全部设置,包括触发器、操作、脚本和配置。

用 AI 创建

打开表格右侧边栏的 AI 对话,告诉 AI 你想要什么。例如: “创建一个自动化,监听订单状态变更,当订单发货时发送 Webhook 通知” AI 会自动创建完整的工作流。你可以查看生成的脚本,用真实数据测试,确认无误后启用。

前提条件

  • 一个个人访问令牌(PAT)。参见访问令牌
  • 你的 Base ID、表格 ID 和字段 ID。参见获取 ID

辅助函数

const baseUrl = "https://app.teable.io/api";
const token = process.env.TEABLE_TOKEN;
const baseId = "bserxxxxxx";

const headers = {
  Authorization: `Bearer ${token}`,
  "Content-Type": "application/json",
};

async function api(method, path, body) {
  const res = await fetch(`${baseUrl}${path}`, {
    method,
    headers,
    body: body ? JSON.stringify(body) : undefined,
  });
  if (!res.ok) throw new Error(`${method} ${path}${res.status}`);
  return res.json();
}

创建工作流

// 1. 创建工作流
const wf = await api("POST", `/base/${baseId}/workflow`, {
  name: "Notify on shipment",
  description: "Send webhook when order status becomes Shipped",
});

// 2. 添加触发器
const trigger = await api("POST", `/base/${baseId}/workflow/${wf.id}/trigger`, {
  type: "recordUpdated",
  config: { tableId: "tblOrders", watchFieldIds: ["fldStatus"] },
});

// 3. 测试触发器
await api("POST", `/base/${baseId}/workflow/${wf.id}/test/${trigger.id}`);

// 4. 添加 HTTP 请求操作
const action = await api("POST", `/base/${baseId}/workflow/${wf.id}/action`, {
  type: "httpRequest",
  parentNodeId: trigger.id,
});

// 5. 启用
await api("PUT", `/base/${baseId}/workflow/${wf.id}/active`, {
  method: "activate",
});

最佳实践

  • 使用最小权限的 PAT——仅授权其所需的空间/Base。
  • 将令牌存储在环境变量中,切勿硬编码。
  • 在启用之前使用测试节点进行验证。
  • 参见完整的自动化 API 参考文档
Last modified on April 9, 2026