Source: https://datafa.st/docs/api/account/alerts/create
Markdown source: https://datafa.st/docs/api/account/alerts/create.md
Description: Create an email alert for a goal.

# Create alert

`POST https://datafa.st/api/v1/admin/websites/{websiteId}/alerts`

Create an email alert for a goal.

## Request

### Authentication

- `dft_` account token with `alerts:write`.


### Path parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `websiteId` | string | Website ObjectId used by account tokens to choose which website to query or manage. Website ObjectId. The caller token must have access to this website. |

### Body parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Human-readable name for the resource or event. The exact meaning depends on the endpoint. |
| `trigger.goalName` | string | Yes | Goal name to watch. Saved lowercase and trimmed. |
| `template.message` | string | Yes | Human-readable confirmation or status message for the operation. |
| `template.subject` | string | No | Custom email subject. |
| `isEnabled` | boolean | No | Defaults to true. Set false to create disabled. |

## Response

Returns a JSON object with `status` and endpoint-specific fields.

### Response fields

| Field | Type | Description |
| --- | --- | --- |
| `data[]._id` | string | Alert ObjectId. |
| `data[].websiteId` | string | Website ObjectId used by account tokens to choose which website to query or manage. |
| `data[].name` | string | Human-readable name for the resource or event. The exact meaning depends on the endpoint. |
| `data[].trigger.type` | string | Trigger type. Currently `goal`. |
| `data[].trigger.goalName` | string | Goal watched by the alert. |
| `data[].destination.type` | string | Destination type. Currently `email`. |
| `data[].template.subject` | string|null | Custom subject when configured. |
| `data[].template.message` | string | Human-readable confirmation or status message for the operation. |
| `data[].isEnabled` | boolean | Whether the alert is enabled. |
| `data[].recentLogs` | object[] | Recent trigger logs. |

### Errors

Common errors include `400` for invalid input, `401` for missing or invalid tokens, `403` for missing permissions or website access, `404` for missing resources, and `500` for server errors.

## Code examples

### Example request

```bash
curl -X POST "https://datafa.st/api/v1/admin/websites/{websiteId}/alerts" \
  -H "Authorization: Bearer dft_xxx" \
  -H "Content-Type: application/json" \
  -d '{"name":"New signup","trigger":{"goalName":"signup"},"template":{"message":"A visitor signed up."},"isEnabled":true}'
```

### Success response

```json
{
  "status": "success",
  "data": [{
    "_id": "665f0b3c4d2e1a0012345678",
    "websiteId": "665f0b3c4d2e1a0012345678",
    "name": "New signup",
    "trigger": { "type": "goal", "goalName": "signup" },
    "destination": { "type": "email" },
    "template": { "subject": "New signup", "message": "A visitor signed up." },
    "isEnabled": true,
    "recentLogs": []
  }]
}
```
