# Delay

> Pause an automation for a fixed duration before continuing to the next step.

A **delay** step pauses the automation for a specified duration before continuing to the next step. See [Using automations](https://www.mailblastr.com/docs/automations/overview) for how steps chain together.

Common use cases:

- **Email sequences** — space out emails in an onboarding series.
- **Cooldowns** — prevent sending too many emails in a short period.
- **Follow-ups** — give users time to take action before sending a reminder.

## How it works

In the dashboard you configure a delay duration in natural language. Over the API, the delay step accepts a single `duration` field with a human-readable time value.

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.create({
  "name": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "wait_1_day",
      "type": "delay",
      "config": { "duration": "1 day" }
    }
  ],
  "connections": [
    { "from": "start", "to": "wait_1_day", "type": "default" }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Automations.create({
  "name": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "wait_1_day",
      "type": "delay",
      "config": {
        "duration": "1 day"
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "wait_1_day",
      "type": "default"
    }
  ]
})
```

**PHP**

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

$mailblastr->automations->create([
  'name' => "Welcome series",
  'domain' => "yourdomain.com",
  'steps' => [
    [
      'key' => "start",
      'type' => "trigger",
      'config' => [
        'event_name' => "user.created"
      ]
    ],
    [
      'key' => "wait_1_day",
      'type' => "delay",
      'config' => [
        'duration' => "1 day"
      ]
    ]
  ],
  'connections' => [
    [
      'from' => "start",
      'to' => "wait_1_day",
      'type' => "default"
    ]
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Automations.create({
  "name": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "wait_1_day",
      "type": "delay",
      "config": {
        "duration": "1 day"
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "wait_1_day",
      "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": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "wait_1_day",
      "type": "delay",
      "config": { "duration": "1 day" }
    }
  ],
  "connections": [
    { "from": "start", "to": "wait_1_day", "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": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "wait_1_day",
      "type": "delay",
      "config": { "duration": "1 day" }
    }
  ],
  "connections": [
    { "from": "start", "to": "wait_1_day", "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": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "wait_1_day",
      "type": "delay",
      "config": { "duration": "1 day" }
    }
  ],
  "connections": [
    { "from": "start", "to": "wait_1_day", "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"": ""Welcome series"",
  ""domain"": ""yourdomain.com"",
  ""steps"": [
    {
      ""key"": ""start"",
      ""type"": ""trigger"",
      ""config"": { ""event_name"": ""user.created"" }
    },
    {
      ""key"": ""wait_1_day"",
      ""type"": ""delay"",
      ""config"": { ""duration"": ""1 day"" }
    }
  ],
  ""connections"": [
    { ""from"": ""start"", ""to"": ""wait_1_day"", ""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": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "wait_1_day",
      "type": "delay",
      "config": { "duration": "1 day" }
    }
  ],
  "connections": [
    { "from": "start", "to": "wait_1_day", "type": "default" }
  ]
}'
```

Example durations: `"30 minutes"`, `"1 hour"`, `"12 hours"`, `"1 day"`, `"3 days"`, `"1 week"`.

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

## Configuration

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `config.duration` | string | Yes | The delay duration in natural language (e.g. `"1 hour"`, `"3 days"`). Maximum: 30 days. |

```json
{
  "key": "wait_1_hour",
  "type": "delay",
  "config": {
    "duration": "1 hour"
  }
}
```
