# API & Automation

Integrate TeamDay into your workflows — API access, CLI scripting, CI/CD pipelines, and scheduled missions.

# API & Automation

TeamDay provides multiple ways to integrate AI agents into your workflows: a REST API, a CLI tool, and scheduled missions.

---

## Access Methods

| Method | Best For |
|--------|---------|
| **[API Keys & Authentication](https://docs.teamday.ai/guides/api-keys)** | Direct API calls, CI/CD pipelines, custom integrations |
| **[CLI Tool](https://docs.teamday.ai/guides/cli-tool)** | Terminal workflows, shell scripts, interactive management |
| **[Missions](https://docs.teamday.ai/guides/missions-user-guide)** | Recurring scheduled tasks (cron, continuous) |

---

## Quick Examples

### Run an Agent via API

```bash
curl -X POST "https://cc.teamday.ai/api/v1/agents/<id>/execute" \
  -H "Authorization: Bearer $TEAMDAY_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"message": "Generate the daily sales report"}'
```

### Run an Agent via CLI

```bash
teamday agents exec <id> "Generate the daily sales report" --space <space-id>
```

### Schedule a Recurring Task

```bash
curl -X POST "https://cc.teamday.ai/api/v1/missions" \
  -H "Authorization: Bearer $TEAMDAY_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Daily Report",
    "goal": "Generate the daily sales report and save to reports/",
    "schedule": {"type": "cron", "value": "0 8 * * *"}
  }'
```

### Provision a Workspace (Script)

```bash
#!/bin/bash
# Automated workspace setup
result=$(teamday spaces create --name "$1" --format json)
id=$(echo "$result" | jq -r '.space.id // .id')
teamday spaces add-skill "$id" core:research-assistant
teamday spaces set-secret "$id" API_KEY="$API_KEY"
echo "Ready: $id"
```

---

## Integration Patterns

### CI/CD Pipeline

Run an agent as part of your deployment process:

```yaml
# GitHub Actions
- name: Post-deploy analysis
  env:
    TEAMDAY_API_TOKEN: ${{ secrets.TEAMDAY_TOKEN }}
  run: |
    teamday agents exec $AGENT_ID \
      "The deployment to production just completed. Run a quick health check." \
      --space $SPACE_ID --no-stream
```

### Webhook-Triggered

Call the TeamDay API from any webhook handler:

```javascript
// Express webhook handler
app.post('/webhook/new-lead', async (req, res) => {
  const { leadEmail, leadName } = req.body;

  await fetch('https://cc.teamday.ai/api/v1/agents/AGENT_ID/execute', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.TEAMDAY_API_TOKEN}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      message: `New lead: ${leadName} (${leadEmail}). Research this person and their company.`,
      spaceId: 'SPACE_ID',
    }),
  });

  res.json({ status: 'ok' });
});
```

### Cron-Based Automation

Use Missions for recurring tasks without external infrastructure:

| Schedule | Mission Example |
|----------|----------------|
| Daily 8am | Generate analytics report |
| Mondays 9am | Weekly SEO audit |
| Hourly | Monitor error rates |
| 1st of month | Monthly performance review |

---

## Next Steps

- [API Keys & Authentication](https://docs.teamday.ai/guides/api-keys) — Set up credentials
- [CLI Tool](https://docs.teamday.ai/guides/cli-tool) — Full command reference
- [Missions User Guide](https://docs.teamday.ai/guides/missions-user-guide) — Scheduled automation
