# Campaigns

> Send template broadcasts to many recipients and track delivery via the WAFlow Public API.

Source: https://edesy.in/docs/waflow/api/campaigns

A campaign sends an approved template to many recipients in one call. WAFlow creates the contacts and a contact list, queues the messages, and reports delivery statistics.

## Send a broadcast

```http
POST /api/v1/send
```

**Required scope:** `campaigns.create`

**Request Body:**
```json
{
  "campaignName": "July Promo",
  "templateName": "promo_july",
  "phoneNumbers": ["+919812345678", "+919812345679"],
  "variables": { "var1": "20%" },
  "sendImmediately": true
}
```

| Field | Type | Description |
|-------|------|-------------|
| `campaignName` | string | A name for the campaign |
| `templateName` | string | Name of an **approved** template |
| `phoneNumbers` | string[] | Recipients in E.164 format (max 1000) |
| `variables` | object | Template variable values, e.g. `{ "var1": "20%" }` |
| `sendImmediately` | boolean | Send now (default `true`) |
| `scheduledFor` | string | ISO‑8601 time to send, when `sendImmediately` is `false` |

**Response:**
```json
{
  "success": true,
  "message": "Campaign started successfully",
  "campaign": {
    "id": 128,
    "name": "July Promo",
    "status": "active",
    "template": { "id": 12, "name": "promo_july" },
    "recipients": { "total": 2, "newContacts": 1, "existingContacts": 1 }
  },
  "tracking": { "campaignId": 128, "statusUrl": "/api/v1/128/status" }
}
```

**cURL Example:**
```bash
curl -X POST "https://waflow.edesy.in/api/v1/send" \
  -H "X-API-Key: wc_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "campaignName": "July Promo",
    "templateName": "promo_july",
    "phoneNumbers": ["+919812345678", "+919812345679"],
    "variables": { "var1": "20%" }
  }'
```

> **Note:** The template must already be approved by Meta. List your approved templates with `GET /api/v1/templates`, or create one via the [Templates API](https://edesy.in/docs/waflow/api/templates).

---

## Get campaign status

```http
GET /api/v1/{campaignId}/status
```

**Required scope:** `campaigns.read`

**Response:**
```json
{
  "success": true,
  "campaign": {
    "id": 128,
    "name": "July Promo",
    "status": "completed",
    "totalRecipients": 2
  },
  "delivery": {
    "sent": 2,
    "delivered": 2,
    "read": 1,
    "replied": 0,
    "failed": 0,
    "pending": 0
  },
  "performance": {
    "deliveryRate": 100,
    "readRate": 50,
    "replyRate": 0
  }
}
```

**cURL Example:**
```bash
curl "https://waflow.edesy.in/api/v1/128/status" \
  -H "X-API-Key: wc_your_api_key"
```

---

## Get notified on completion

Instead of polling, subscribe to the `campaign.completed` [webhook](https://edesy.in/docs/waflow/api/webhooks) to be notified with final statistics as soon as a campaign finishes.
