# Email an alert when a Run fails

Build an automation that emails your team when a Run fails. Reecall produces a [`run.failed` System event](/docs/system-events#runfailed) each time a Run ends with `status: "failed"`. A Trigger on it starts a Process that emails why the Run failed.

The System event gives the error code, a sentence that describes the failure, and the position of the failed step. The sentence never holds the Run's data, such as a response body or a value from the conversation.

## Prerequisites

- An [API key](/docs/authentication). A project-scoped key watches the Runs of its Project. An organization-scoped key can watch every Project of the Organization.
- The email address that receives the alerts.

## Step 1: Create the Process

The Process has one [Email step](/docs/email) that sends the fields of the System event:

```bash title="Create the Process"
curl https://data.reecall.io/automation/processes \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "name": "Run failure alert",
    "description": "Email the team when a Run fails",
    "steps": [
      {
        "type": "email",
        "config": {
          "to": "ops@example.com",
          "fromName": "Reecall alerts",
          "subject": "Run failed: {{ event.data.errorCode }}",
          "textPart": "A Run failed.\n\n{{ event.data.errorMessage }}\n\nRun: {{ event.refId }}\nTrigger: {{ event.data.triggerId }}\nProcess: {{ event.data.processId }}\nError: {{ event.data.errorCode }}\nFailed step: {{ event.data.failedStep }}\nAt: {{ event.occurredAt }}"
        }
      }
    ]
  }'
```

Replace `to` with your address. Without `from`, the email comes from `noreply@reecall.co`.

A field that has no value renders as empty text, such as `processId` for a Run of steps sent with the API call.

Copy the `id` of the response for the next step.

## Step 2: Create the Trigger

Link the Process to `run.failed`:

```bash title="Create the Trigger"
curl https://data.reecall.io/automation/triggers \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "name": "Run failure alert",
    "eventType": "run.failed",
    "processId": "<your-process-id>"
  }'
```

With a project-scoped key, the Trigger receives the failures of its Project. With an organization-scoped key, create the Process and the Trigger without `projectId` to receive the failures of every Project. See [Scope](/docs/triggers#scope).

### Watch one Trigger only

To be alerted only for the Runs of one Trigger, such as the one from [Send a call report to a webhook](/docs/call-report-webhook), add a condition on `event.data.triggerId`:

```json title="Conditions"
{
  "operator": "AND",
  "conditions": [
    { "source": "event.data.triggerId", "filter": "EQUALS", "value": "<watched-trigger-id>" }
  ]
}
```

## Step 3: Make a Run fail

Start a Run of one request step whose host does not exist. The `.invalid` domain never resolves, so the step fails at once:

```bash title="Start a Run that fails"
curl https://workflows.reecall.io/v2/execute \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "steps": [
      { "type": "request", "config": { "url": "https://reecall-test.invalid", "method": "GET" } }
    ]
  }'
```

The Run ends with `status: "failed"`, `errorCode: "REQUEST_ERROR"`, and `errorMessage: "The host name could not be resolved"`. Reecall produces `run.failed`, and your Trigger starts the alert Process. Skip this step if you added the condition on `triggerId`: a Run started through the API has no Trigger, so the condition does not match.

## Step 4: Check the alert

Read the Runs of the alert Trigger:

```bash title="List the Runs of the alert Trigger"
curl 'https://workflows.reecall.io/v2/runs?triggerId=<your-trigger-id>' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY'
```

The newest Run has `status: "succeeded"`, and its `refId` is the ID of the failed Run. The email reaches your inbox.

## Result

When a Run of the [call report](/docs/call-report-webhook) Process fails because your endpoint answered `503`, the alert looks like this:

```text title="Email"
Subject: Run failed: REQUEST_ERROR

A Run failed.

Request failed with status code 503 (Service Unavailable)

Run: 5d1f0c8e-2b7a-4e3d-9c6f-8a1b2c3d4e5f
Trigger: 9e8d7c6b-5a4f-4e3d-8c2b-1a0f9e8d7c6b
Process: 3c4d5e6f-7a8b-4c9d-8e1f-2a3b4c5d6e7f
Error: REQUEST_ERROR
Failed step: 1
At: 2026-12-01T10:15:47.902Z
```

Step `1` is the Request step of the call report Process. A `503` is safe to repeat, so turning on [retries](/docs/triggers#retry-policy) for the call report Trigger would have tried again before alerting.

- A Run with [retries](/docs/runs#retries) produces `run.failed` once, when its last attempt fails.
- If the alert Process fails, no other alert follows: a Run started by `run.failed` never produces `run.failed`.
- To see how each step of the failed Run went, read the Run with `GET /v2/runs/{id}`. See [Step records](/docs/runs#step-records).

## Troubleshooting

| Symptom | Check |
| --- | --- |
| No alert Run after the failure | The Trigger's `enabled` field, its `eventType`, and its scope. A project Trigger only receives the failures of its Project. |
| The alert Run failed with `EMAIL_ERROR` | The alert Run's `errorMessage`, the `to` address, and `from` if you set one. See [Email](/docs/email#error-handling). |
| The alert Run succeeded but no email arrived | The spam folder of the recipient. The step's status reports the provider's acceptance, not the delivery. |
