# REST API and webhooks

Base URL: `https://studio.simpragma.com/api`

## Authentication

Create a key in **Dashboard → API keys** and choose its scopes:

| Scope | Allows |
|---|---|
| `read` | Read templates, campaigns, runs, calls, usage |
| `write` | Create and change agents, campaigns, runs, contacts, numbers |
| `dial` | Launch, pause and resume runs |

Send it as a Bearer token:

```bash
curl https://studio.simpragma.com/api/campaigns -H "Authorization: Bearer bk_..."
```

Rate limit: 120 requests a minute per key; dial actions 10 a minute.

## Typical flow

```bash
API=https://studio.simpragma.com/api; KEY="Authorization: Bearer bk_..."

# 1. Pick a template
curl -s "$API/templates" -H "$KEY"

# 2. Create a campaign from it
curl -s -X POST "$API/campaigns" -H "$KEY" -H "Content-Type: application/json" \
  -d '{"name":"October reminders","template_id":"<template id>","voice_bot":{"agent_name":"Ava","company_name":"Riverside Dental"}}'

# 3. Create a run
curl -s -X POST "$API/campaigns/$CAMPAIGN/runs" -H "$KEY" -H "Content-Type: application/json" \
  -d '{"name":"Tuesday batch","start_date":"2026-10-21"}'

# 4. Add contacts (CSV in JSON)
curl -s -X POST "$API/campaigns/$CAMPAIGN/runs/$RUN/contacts" -H "$KEY" -H "Content-Type: application/json" \
  -d '{"csv_content":"phone,customer_name,appointment_date\n+447700900123,James Morgan,Wednesday 9:15"}'

# 5. Launch — without confirmation it returns the pre-launch check (400 CONFIRMATION_REQUIRED)
curl -s -X POST "$API/campaigns/$CAMPAIGN/runs/$RUN/launch" -H "$KEY"

# 6. Confirm with the attestation id from step 5
curl -s -X POST "$API/campaigns/$CAMPAIGN/runs/$RUN/launch" -H "$KEY" -H "Content-Type: application/json" \
  -d '{"confirm":true,"attestation":"<attestation id>"}'
```

## Endpoints

| Method | Path | Scope |
|---|---|---|
| GET | `/templates`, `/templates/{id}` | read |
| GET, POST | `/campaigns` | read, write |
| GET, PUT, DELETE | `/campaigns/{id}` | read, write |
| GET, PATCH | `/campaigns/{id}/voice` | read, write |
| GET, POST | `/campaigns/{id}/runs` | read, write |
| GET | `/campaigns/{id}/runs/{runId}` | read |
| GET, POST | `/campaigns/{id}/runs/{runId}/contacts` | read, write |
| POST | `/campaigns/{id}/runs/{runId}/launch` · `/pause` · `/resume` | dial |
| GET | `/calls`, `/calls/{id}` | read |
| GET | `/wallet` | read |
| GET, POST | `/phone-numbers` | read, write |

An agent's voice: send `voice` (`"female"` or `"male"`) when you create a campaign, or `PATCH /campaigns/{id}/voice` with `{"voice": "male"}` (`"default"` goes back to the standard voice). UK and US workspaces; India returns a validation error for now. `GET` shows the current voice and the options, plus a hint when the agent's name looks like the other gender.

Errors are JSON with an `error` field (a code and message).

## Webhooks

Set a webhook URL on a campaign (the campaign's **Integrations** tab). After each **answered** call, Breeze sends a `POST` with JSON:

```json
{
  "event": "lead_qualified",
  "contact": { "id": "…", "phone": "+447700900123", "first_name": "James", "last_name": "Morgan", "appointment_date": "Wednesday 9:15" },
  "outcome": "<outcome code for this agent>",
  "outcome_data": { "summary": "Asked for Thursday morning instead" },
  "campaign": { "id": "…", "name": "October reminders" },
  "run": { "id": "…", "name": "Tuesday batch" },
  "called_at": "2026-10-21T09:32:11Z"
}
```

Respond with any `2xx`. Delivery is best-effort (no retries yet), so poll `/calls` if you need a complete record.
