> ## Documentation Index
> Fetch the complete documentation index at: https://help.teable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Build automations programmatically with the API

> Create and configure workflows using the Teable API and JavaScript

<Tip>We recommend building automation examples directly in AI chat. Just describe the workflow you want, and AI will handle the full setup for you, including the trigger, actions, script, and configuration.</Tip>

## Build with AI

Open the AI Chat in your table's right sidebar and tell AI what you want. For example, you can say:

*"Create an automation that watches for order status changes and sends a webhook notification when an order ships"*

AI will create the complete workflow automatically. You can review the generated script, test it with real data, and enable the workflow when ready.

## Prerequisites

* A Personal Access Token (PAT). See [Access Token](/en/api-doc/token).
* Your base ID, table ID, and field IDs. See [Get IDs](/en/api-doc/get-id).

## Helper Functions

```javascript theme={null}
const baseUrl = "https://app.teable.ai/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();
}
```

## Create the Workflow

```javascript theme={null}
// 1. Create a workflow
const wf = await api("POST", `/base/${baseId}/workflow`, {
  name: "Notify on shipment",
  description: "Send webhook when order status becomes Shipped",
});

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

// 3. Test the trigger
await api("POST", `/base/${baseId}/workflow/${wf.id}/test/${trigger.id}`);

// 4. Add an HTTP Request action
const action = await api("POST", `/base/${baseId}/workflow/${wf.id}/action`, {
  type: "httpRequest",
  parentNodeId: trigger.id,
});

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

## Best Practices

* Use the least-privileged PAT — restrict it to the spaces/bases it needs.
* Store tokens in environment variables, never hardcode them.
* Use **Test Node** to verify before enabling.
* See the full [Automation API Reference](/en/api-reference/automation/put-base-workflow-action).
