# Add Automation Step

> POST /automations/:id/steps — append a step to a disabled automation.

`POST /automations/:id/steps`

Appends a step to an automation. The automation must be **disabled** — [stop](https://www.mailblastr.com/docs/api/automations-stop) or disable it first. Returns the created step.

Supported step types (see the [Steps](https://www.mailblastr.com/docs/automations/steps) page for full config shapes):

- **[send_email](https://www.mailblastr.com/docs/automations/send-email)** — send a published template; `config.template.id` is required, with optional `variables`, `from`, `subject`, and `reply_to`.
- **[delay](https://www.mailblastr.com/docs/automations/delay)** — pause for a natural-language `duration` (e.g. `"1 day"`). Maximum 30 days.
- **[wait_for_event](https://www.mailblastr.com/docs/automations/wait-for-event)** — pause until `event_name` is received, with an optional `timeout` and `filter_rule`.
- **[condition](https://www.mailblastr.com/docs/automations/condition)** — branch on a `rule` (or an `and`/`or` group of rules) evaluated against `event.*` / `contact.*` data.
- **[contact_update](https://www.mailblastr.com/docs/automations/contact-update)** — update the contact's `first_name`, `last_name`, `unsubscribed`, or `properties`.
- **[contact_delete](https://www.mailblastr.com/docs/automations/contact-delete)** — delete the contact; `config` is an empty object `{}`.
- **[add_to_segment](https://www.mailblastr.com/docs/automations/add-to-segment)** — add the contact to a segment; requires `config.segment_id`.

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.addStep('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd', { "type": "delay", "config": { "duration": "1 day" } });
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Automations.add_step("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", {
  "type": "delay",
  "config": {
    "duration": "1 day"
  }
})
```

**PHP**

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

$mailblastr->automations->addStep('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd', [
  'type' => "delay",
  'config' => [
    'duration' => "1 day"
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Automations.add_step("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", {
  "type": "delay",
  "config": {
    "duration": "1 day"
  }
})
```

**Go**

```go
package main

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

func main() {
    req, _ := http.NewRequest("POST", "https://api.mailblastr.com/automations/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps", strings.NewReader(`{ "type": "delay", "config": { "duration": "1 day" } }`))
    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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{ "type": "delay", "config": { "duration": "1 day" } }"#)
        .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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("""
{ "type": "delay", "config": { "duration": "1 day" } }
"""))
    .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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{ ""type"": ""delay"", ""config"": { ""duration"": ""1 day"" } }", 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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "type": "delay", "config": { "duration": "1 day" } }'
```

**CLI**

```bash
mailblastr automations add-step c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd \
  --type 'delay' \
  --config '{"duration":"1 day"}'
```

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.addStep('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd', {
  "type": "send_email",
  "key": "welcome",
  "config": { "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" } }
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Automations.add_step("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", {
  "type": "send_email",
  "key": "welcome",
  "config": {
    "template": {
      "id": "34a080c9-b17d-4187-ad80-5af20266e535"
    }
  }
})
```

**PHP**

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

$mailblastr->automations->addStep('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd', [
  'type' => "send_email",
  'key' => "welcome",
  'config' => [
    'template' => [
      'id' => "34a080c9-b17d-4187-ad80-5af20266e535"
    ]
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Automations.add_step("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", {
  "type": "send_email",
  "key": "welcome",
  "config": {
    "template": {
      "id": "34a080c9-b17d-4187-ad80-5af20266e535"
    }
  }
})
```

**Go**

```go
package main

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

func main() {
    req, _ := http.NewRequest("POST", "https://api.mailblastr.com/automations/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps", strings.NewReader(`{
  "type": "send_email",
  "key": "welcome",
  "config": { "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" } }
}`))
    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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{
  "type": "send_email",
  "key": "welcome",
  "config": { "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" } }
}"#)
        .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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("""
{
  "type": "send_email",
  "key": "welcome",
  "config": { "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" } }
}
"""))
    .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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{
  ""type"": ""send_email"",
  ""key"": ""welcome"",
  ""config"": { ""template"": { ""id"": ""34a080c9-b17d-4187-ad80-5af20266e535"" } }
}", 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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "type": "send_email",
  "key": "welcome",
  "config": { "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" } }
}'
```

**CLI**

```bash
mailblastr automations add-step c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd \
  --type 'send_email' \
  --key 'welcome' \
  --config '{"template":{"id":"34a080c9-b17d-4187-ad80-5af20266e535"}}'
```

### Response

```json
{
  "id": "9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d",
  "key": "welcome",
  "type": "send_email",
  "position": 0,
  "config": { "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" } }
}
```
