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

# Code Examples

> Working cURL and Node.js examples for common Tedro API operations.

# Code Examples

Copy-paste examples for the most common API operations. All examples assume you have already [authenticated](/api-reference/authentication) and have your session token and workspace ID ready.

For cURL examples, we assume:

* Session cookie saved to `cookies.txt` (via `curl -c cookies.txt` during sign-in)
* Workspace ID exported as `$WORKSPACE_ID`

For Node.js examples, we assume:

* `sessionToken` contains your `better-auth.session_token` value
* `workspaceId` contains your workspace UUID

## Workflows

### List All Workflows

```bash cURL theme={null}
curl https://api.tedro.io/api/workflows \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID"
```

```javascript Node.js theme={null}
const res = await fetch('https://api.tedro.io/api/workflows', {
  headers: {
    'Cookie': `better-auth.session_token=${sessionToken}`,
    'x-workspace-id': workspaceId,
  },
});
const { items } = await res.json();
```

### Create a Workflow

```bash cURL theme={null}
curl -X POST https://api.tedro.io/api/workflows \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"name": "My New Workflow"}'
```

```javascript Node.js theme={null}
const res = await fetch('https://api.tedro.io/api/workflows', {
  method: 'POST',
  headers: {
    'Cookie': `better-auth.session_token=${sessionToken}`,
    'x-workspace-id': workspaceId,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: 'My New Workflow' }),
});
const workflow = await res.json();
```

### Publish a Workflow

```bash cURL theme={null}
curl -X POST https://api.tedro.io/api/workflows/{workflowId}/publish \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```javascript Node.js theme={null}
const res = await fetch(
  `https://api.tedro.io/api/workflows/${workflowId}/publish`,
  {
    method: 'POST',
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
      'Content-Type': 'application/json',
    },
    body: '{}',
  }
);
```

## Contacts

### List Contacts (with Pagination)

```bash cURL theme={null}
curl "https://api.tedro.io/api/contacts?limit=20&offset=0" \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID"
```

```javascript Node.js theme={null}
const res = await fetch(
  'https://api.tedro.io/api/contacts?limit=20&offset=0',
  {
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
    },
  }
);
const { items, total } = await res.json();
```

### Create a Contact

```bash cURL theme={null}
curl -X POST https://api.tedro.io/api/contacts \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Jane Doe",
    "phone": "+14155551234"
  }'
```

```javascript Node.js theme={null}
const res = await fetch('https://api.tedro.io/api/contacts', {
  method: 'POST',
  headers: {
    'Cookie': `better-auth.session_token=${sessionToken}`,
    'x-workspace-id': workspaceId,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Jane Doe',
    phone: '+14155551234',
  }),
});
const contact = await res.json();
```

### Update a Contact

```bash cURL theme={null}
curl -X PATCH https://api.tedro.io/api/contacts/{contactId} \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"name": "Jane Smith"}'
```

```javascript Node.js theme={null}
const res = await fetch(
  `https://api.tedro.io/api/contacts/${contactId}`,
  {
    method: 'PATCH',
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ name: 'Jane Smith' }),
  }
);
```

## Conversations

### List Conversations

```bash cURL theme={null}
curl "https://api.tedro.io/api/conversations?limit=10&offset=0" \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID"
```

```javascript Node.js theme={null}
const res = await fetch(
  'https://api.tedro.io/api/conversations?limit=10&offset=0',
  {
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
    },
  }
);
const { items, total } = await res.json();
```

### Get Conversation Messages

```bash cURL theme={null}
curl https://api.tedro.io/api/conversations/{conversationId}/messages \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID"
```

```javascript Node.js theme={null}
const res = await fetch(
  `https://api.tedro.io/api/conversations/${conversationId}/messages`,
  {
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
    },
  }
);
const { messages } = await res.json();
```

### Send a Message in a Conversation

```bash cURL theme={null}
curl -X POST https://api.tedro.io/api/conversations/{conversationId}/messages \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"body": "Hello! How can I help you today?"}'
```

```javascript Node.js theme={null}
const res = await fetch(
  `https://api.tedro.io/api/conversations/${conversationId}/messages`,
  {
    method: 'POST',
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      body: 'Hello! How can I help you today?',
    }),
  }
);
```

<Warning>
  For WhatsApp conversations, sending messages is subject to the 24-hour customer service window. Messages can only be sent within 24 hours of the customer's last inbound message. Outside this window, use approved message templates via broadcasts. Other channels (Instagram, Messenger, Live Chat) have their own messaging policies.
</Warning>

## Runs

### List Recent Runs

```bash cURL theme={null}
curl "https://api.tedro.io/api/runs?limit=10&offset=0" \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID"
```

```javascript Node.js theme={null}
const res = await fetch(
  'https://api.tedro.io/api/runs?limit=10&offset=0',
  {
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
    },
  }
);
const { items, total } = await res.json();
```

### Get Run Details and Steps

```bash cURL theme={null}
# Get run overview
curl https://api.tedro.io/api/runs/{runId} \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID"

# Get execution steps
curl https://api.tedro.io/api/runs/{runId}/steps \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID"
```

```javascript Node.js theme={null}
// Get run overview
const runRes = await fetch(
  `https://api.tedro.io/api/runs/${runId}`,
  {
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
    },
  }
);
const run = await runRes.json();

// Get execution steps
const stepsRes = await fetch(
  `https://api.tedro.io/api/runs/${runId}/steps`,
  {
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
    },
  }
);
const { steps } = await stepsRes.json();
```

### Replay a Run

```bash cURL theme={null}
curl -X POST https://api.tedro.io/api/runs/{runId}/replay \
  -b cookies.txt \
  -H "x-workspace-id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```javascript Node.js theme={null}
const res = await fetch(
  `https://api.tedro.io/api/runs/${runId}/replay`,
  {
    method: 'POST',
    headers: {
      'Cookie': `better-auth.session_token=${sessionToken}`,
      'x-workspace-id': workspaceId,
      'Content-Type': 'application/json',
    },
    body: '{}',
  }
);
```
