# Wait for Event

> Hold an automation until a specific event arrives, with an optional timeout and filter rule.

A **wait for event** step holds the automation until a specific event is received. Unlike a [delay](https://www.mailblastr.com/docs/automations/delay), which resumes after a fixed time, this step resumes when something happens in your application.

See [Using automations](https://www.mailblastr.com/docs/automations/overview) for the surrounding workflow.

Common use cases:

- **Payment** — wait for a payment to succeed before sending a receipt.
- **Adoption** — wait for a user to complete an action to unlock a feature.
- **Verification** — wait for the user to verify their email before continuing.

## How it works

Add a `wait_for_event` step to the `steps` array, naming the event to wait for and an optional `timeout`.

**Node.js**

```js
import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.create({
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "verification", "type": "default" }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Automations.create({
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "verification",
      "type": "default"
    }
  ]
})
```

**PHP**

```php
$mailblastr = Mailblastr::client('mb_xxxxxxxxx');

$mailblastr->automations->create([
  'name' => "Verification reminder",
  'domain' => "yourdomain.com",
  'steps' => [
    [
      'key' => "start",
      'type' => "trigger",
      'config' => [
        'event_name' => "user.created"
      ]
    ],
    [
      'key' => "verification",
      'type' => "wait_for_event",
      'config' => [
        'event_name' => "email.verified",
        'timeout' => "1 day"
      ]
    ]
  ],
  'connections' => [
    [
      'from' => "start",
      'to' => "verification",
      'type' => "default"
    ]
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Automations.create({
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "verification",
      "type": "default"
    }
  ]
})
```

**Go**

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    req, _ := http.NewRequest("POST", "https://api.mailblastr.com/automations", strings.NewReader(`{
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "verification", "type": "default" }
  ]
}`))
    req.Header.Set("Authorization", "Bearer mb_xxxxxxxxx")
    req.Header.Set("Content-Type", "application/json")
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    out, _ := io.ReadAll(res.Body)
    fmt.Println(string(out))
}
```

**Rust**

```rust
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let res = Client::new()
        .post("https://api.mailblastr.com/automations")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "verification", "type": "default" }
  ]
}"#)
        .send()
        .await?;
    println!("{}", res.text().await?);
    Ok(())
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mailblastr.com/automations"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("""
{
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "verification", "type": "default" }
  ]
}
"""))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**.NET**

```csharp
using System.Net.Http;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.mailblastr.com/automations");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{
  ""name"": ""Verification reminder"",
  ""domain"": ""yourdomain.com"",
  ""steps"": [
    {
      ""key"": ""start"",
      ""type"": ""trigger"",
      ""config"": { ""event_name"": ""user.created"" }
    },
    {
      ""key"": ""verification"",
      ""type"": ""wait_for_event"",
      ""config"": {
        ""event_name"": ""email.verified"",
        ""timeout"": ""1 day""
      }
    }
  ],
  ""connections"": [
    { ""from"": ""start"", ""to"": ""verification"", ""type"": ""default"" }
  ]
}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

**cURL**

```bash
curl -X POST 'https://api.mailblastr.com/automations' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "verification", "type": "default" }
  ]
}'
```

## Timeouts

When you set a `timeout`, the step stops waiting after that duration, which prevents automations from waiting indefinitely. A wait-for-event step produces two possible connection types so you can branch on whether the event arrived in time:

| Connection type | When it is used |
| --- | --- |
| `event_received` | The event arrived before the timeout. |
| `timeout` | The timeout elapsed without receiving the event. |

```json
{
  "key": "payment",
  "type": "wait_for_event",
  "config": {
    "event_name": "payment.completed",
    "timeout": "3 days"
  }
}
```

> **Warning:** The maximum timeout is **30 days**.

## Filter rules

Use `filter_rule` to match only events that meet specific criteria — useful when the same event name is sent with different payloads. The rule is evaluated against the incoming event's payload. For example, to wait specifically for a successful payment:

```json
{
  "key": "payment",
  "type": "wait_for_event",
  "config": {
    "event_name": "payment.completed",
    "filter_rule": {
      "type": "rule",
      "field": "event.status",
      "operator": "eq",
      "value": "succeeded"
    }
  }
}
```

The filter rule supports the same rule shapes and [operators](https://www.mailblastr.com/docs/automations/condition) as [condition](https://www.mailblastr.com/docs/automations/condition) steps — including `and`/`or` groups.

## Configuration

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `config.event_name` | string | Yes | The name of the event to wait for. |
| `config.timeout` | string | No | The maximum time to wait before timing out (e.g. `"3 days"`, `"1 hour"`). Maximum: 30 days. |
| `config.filter_rule` | object | No | An optional rule object to filter incoming events. Uses the same shape as a condition rule. |
