# Automations

> Automate emails with custom events.

Automations allow you to **create email steps** based on custom events from your application.

You can use automations for use cases like:

- Welcome emails
- Drip campaigns
- Payment recovery
- Abandoned cart
- Trial expiration

Automations support `{{{SENDPING_UNSUBSCRIBE_URL}}}` for compliance with non-transactional product and marketing messaging.

## How it works

To start executing an automation, you need to:

1. **Create Automation** — Outline the sequence of steps to be executed.
2. **Add Trigger** — Define the [event name](https://www.sendping.co/docs/automations/trigger) that will trigger the automation.
3. **Define Steps** — Configure the [steps](https://www.sendping.co/docs/automations/steps) to be executed.
4. **Send an Event** — Trigger the automation by sending an event from your application.
5. **Monitor Runs** — Track and debug your automation executions using [runs](https://www.sendping.co/docs/automations/runs).

## 1. Create an automation

The **Automations** page in the dashboard shows all existing automations. You can search by name and filter by status (**All Statuses**, **Enabled**, or **Disabled**) to quickly find the automation you need. Click **Create automation** to start a new automation.

An automation is either **enabled** or **disabled**. New automations start out disabled; only enabled automations create runs when a matching event is received.

Over the API, you can create an entire automation flow with a single request (`status` is optional and defaults to `disabled`):

- `name` — the name of the automation.
- `domain` — **required**: the sending domain this automation belongs to (one of your domains). Only [events](https://www.sendping.co/docs/api/events-send) sent with the same `domain` trigger it.
- `status` — the status of the automation (`enabled` or `disabled`).
- `steps` — the [steps](https://www.sendping.co/docs/automations/steps) that compose the automation graph.
- `connections` — the [connections between steps](https://www.sendping.co/docs/automations/connections) in the automation graph.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('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": "welcome",
      "type": "send_email",
      "config": {
        "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" }
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "welcome" }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Automations.create({
  "name": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "welcome",
      "type": "send_email",
      "config": {
        "template": {
          "id": "34a080c9-b17d-4187-ad80-5af20266e535"
        }
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "welcome"
    }
  ]
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->automations->create([
  'name' => "Welcome series",
  'domain' => "yourdomain.com",
  'steps' => [
    [
      'key' => "start",
      'type' => "trigger",
      'config' => [
        'event_name' => "user.created"
      ]
    ],
    [
      'key' => "welcome",
      'type' => "send_email",
      'config' => [
        'template' => [
          'id' => "34a080c9-b17d-4187-ad80-5af20266e535"
        ]
      ]
    ]
  ],
  'connections' => [
    [
      'from' => "start",
      'to' => "welcome"
    ]
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Automations.create({
  "name": "Welcome series",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "welcome",
      "type": "send_email",
      "config": {
        "template": {
          "id": "34a080c9-b17d-4187-ad80-5af20266e535"
        }
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "welcome"
    }
  ]
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

automation, err := client.Automations.Create(&sendping.CreateAutomationRequest{
    Name:   "Welcome series",
    Domain: "yourdomain.com",
    Steps: []sendping.AutomationStepInput{
        {
            Key:    "start",
            Type:   "trigger",
            Config: map[string]any{"event_name": "user.created"},
        },
        {
            Key:  "welcome",
            Type: "send_email",
            Config: map[string]any{
                "template": map[string]any{"id": "34a080c9-b17d-4187-ad80-5af20266e535"},
            },
        },
    },
    Connections: []sendping.AutomationConnectionInput{{From: "start", To: "welcome"}},
})
```

**Rust**

```rust
use sendping::{AutomationStepInput, ConnectionInput, CreateAutomationOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = CreateAutomationOptions::new("Welcome series", "yourdomain.com")
    .with_step(AutomationStepInput::new("trigger")
        .with_key("start")
        .with_config(serde_json::json!({"event_name":"user.created"})))
    .with_step(AutomationStepInput::new("send_email")
        .with_key("welcome")
        .with_config(serde_json::json!({
            "template": {
                "id": "34a080c9-b17d-4187-ad80-5af20266e535"
            }
        })))
    .with_connection(ConnectionInput::new("start", "welcome"));
let _automation = mb.automations.create(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.AutomationConnection;
import co.sendping.requests.AutomationStep;
import co.sendping.requests.CreateAutomationRequest;
import java.util.Map;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

CreateAutomationRequest request = CreateAutomationRequest.builder()
        .name("Welcome series")
        .domain("yourdomain.com")
        .step(AutomationStep.builder()
                .key("start")
                .type("trigger")
                .config("event_name", "user.created")
                .build())
        .step(AutomationStep.builder()
                .key("welcome")
                .type("send_email")
                .config("template", Map.of("id", "34a080c9-b17d-4187-ad80-5af20266e535"))
                .build())
        .connection(AutomationConnection.of("start", "welcome"))
        .build();

SendPingResponse response = sendping.automations().create(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.AutomationCreateAsync(new AutomationCreateOptions
{
    Name = "Welcome series",
    Domain = "yourdomain.com",
    Steps = new List<AutomationStepInput>
    {
        new()
        {
            Key = "start",
            Type = "trigger",
            Config = new Dictionary<string, object?>
            {
                ["event_name"] = "user.created",
            },
        },
        new()
        {
            Key = "welcome",
            Type = "send_email",
            Config = new Dictionary<string, object?>
            {
                ["template"] = new Dictionary<string, object?>
                {
                    ["id"] = "34a080c9-b17d-4187-ad80-5af20266e535",
                },
            },
        },
    },
    Connections = new List<AutomationConnection>
    {
        new() { From = "start", To = "welcome" },
    },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/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": "welcome",
      "type": "send_email",
      "config": {
        "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" }
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "welcome" }
  ]
}'
```

The [trigger](https://www.sendping.co/docs/automations/trigger) is defined as the first item in the `steps` array with `type: "trigger"`. `domain` ties the automation to one of your sending domains — only events sent with that `domain` trigger it, so running several products on one account can never cross-fire automations. For more help creating an automation via the API, see the [Create Automation API reference](https://www.sendping.co/docs/api/automations-create).

> **Note:** Creating an automation with `status: "enabled"` requires at least one step besides the trigger.

## 2. Define steps

There are several [step types](https://www.sendping.co/docs/automations/steps) you can add to your automation:

| Step type | Description |
| --- | --- |
| [Condition](https://www.sendping.co/docs/automations/condition) | Branches the workflow based on rules. |
| A/B split | Randomly splits contacts between two branches by a percentage (deterministic per contact). Add a step with `type: "split"` and `config.percent` — branch A rides the True edge, branch B the False edge. |
| [Delay](https://www.sendping.co/docs/automations/delay) | Pauses execution for a specified duration. |
| [Wait for Event](https://www.sendping.co/docs/automations/wait-for-event) | Pauses execution until a specific event is received. |
| [Send Email](https://www.sendping.co/docs/automations/send-email) | Sends an email using a template. |
| [Contact Update](https://www.sendping.co/docs/automations/contact-update) | Updates a contact's fields. |
| [Contact Delete](https://www.sendping.co/docs/automations/contact-delete) | Deletes the contact. |
| [Add to Segment](https://www.sendping.co/docs/automations/add-to-segment) | Adds the contact to a segment. |

## 3. Send an event

Trigger the automation by sending an event from your application. `domain` names the sending domain the event belongs to — only that domain's automations fire. Identify the contact with a `contact_id` or an `email`.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.events.send({
  "event": "user.created",
  "domain": "yourdomain.com",
  "contact_id": "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
  "payload": {
    "plan": "pro"
  }
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Events.send({
  "event": "user.created",
  "domain": "yourdomain.com",
  "contact_id": "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
  "payload": {
    "plan": "pro"
  }
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->events->send([
  'event' => "user.created",
  'domain' => "yourdomain.com",
  'contact_id' => "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
  'payload' => [
    'plan' => "pro"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Events.send({
  "event": "user.created",
  "domain": "yourdomain.com",
  "contact_id": "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
  "payload": {
    "plan": "pro"
  }
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

event, err := client.Events.Send(&sendping.SendEventRequest{
    Event:     "user.created",
    Domain:    "yourdomain.com",
    ContactId: "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
    Payload:   map[string]any{"plan": "pro"},
})
```

**Rust**

```rust
use sendping::{SendEventOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = SendEventOptions::new("user.created", "yourdomain.com")
    .with_contact_id("7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b")
    .with_payload_entry("plan", serde_json::json!("pro"));
let _event = mb.events.send(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.SendEventRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendEventRequest request = SendEventRequest.builder()
        .event("user.created")
        .domain("yourdomain.com")
        .contactId("7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b")
        .payload("plan", "pro")
        .build();

SendPingResponse response = sendping.events().send(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EventSendAsync(new EventSendOptions
{
    Event = "user.created",
    Domain = "yourdomain.com",
    ContactId = "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
    Payload = new Dictionary<string, object?> { ["plan"] = "pro" },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/events/send' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "event": "user.created",
  "domain": "yourdomain.com",
  "contact_id": "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
  "payload": {
    "plan": "pro"
  }
}'
```

**CLI**

```bash
sendping events send \
  --name 'user.created' \
  --domain 'yourdomain.com' \
  --contact-id '7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b' \
  --data '{"plan":"pro"}'
```

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.events.send({
  "event": "user.created",
  "domain": "yourdomain.com",
  "email": "user@example.com",
  "payload": {
    "plan": "pro"
  }
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Events.send({
  "event": "user.created",
  "domain": "yourdomain.com",
  "email": "user@example.com",
  "payload": {
    "plan": "pro"
  }
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->events->send([
  'event' => "user.created",
  'domain' => "yourdomain.com",
  'email' => "user@example.com",
  'payload' => [
    'plan' => "pro"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Events.send({
  "event": "user.created",
  "domain": "yourdomain.com",
  "email": "user@example.com",
  "payload": {
    "plan": "pro"
  }
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

event, err := client.Events.Send(&sendping.SendEventRequest{
    Event:   "user.created",
    Domain:  "yourdomain.com",
    Email:   "user@example.com",
    Payload: map[string]any{"plan": "pro"},
})
```

**Rust**

```rust
use sendping::{SendEventOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = SendEventOptions::new("user.created", "yourdomain.com")
    .with_email("user@example.com")
    .with_payload_entry("plan", serde_json::json!("pro"));
let _event = mb.events.send(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.SendEventRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendEventRequest request = SendEventRequest.builder()
        .event("user.created")
        .domain("yourdomain.com")
        .email("user@example.com")
        .payload("plan", "pro")
        .build();

SendPingResponse response = sendping.events().send(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EventSendAsync(new EventSendOptions
{
    Event = "user.created",
    Domain = "yourdomain.com",
    Email = "user@example.com",
    Payload = new Dictionary<string, object?> { ["plan"] = "pro" },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/events/send' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "event": "user.created",
  "domain": "yourdomain.com",
  "email": "user@example.com",
  "payload": {
    "plan": "pro"
  }
}'
```

**CLI**

```bash
sendping events send \
  --name 'user.created' \
  --domain 'yourdomain.com' \
  --email 'user@example.com' \
  --data '{"plan":"pro"}'
```

View the [Send Event API reference](https://www.sendping.co/docs/api/events-send) for more details.

## 4. Monitor runs

After sending events, track your automation executions through runs. Each time an event triggers an automation, a run is created to track the execution.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.automations.runs('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd');
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Automations.runs("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd")
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->automations->runs('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd');
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Automations.runs("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd")
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

runs, err := client.Automations.Runs("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", nil)
```

**Rust**

```rust
use sendping::SendPing;

let mb = SendPing::new("mb_xxxxxxxxx");

let _runs = mb.automations.runs("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", None).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendPingResponse response = sendping.automations().runs("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd");
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.AutomationListRunsAsync("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd");
```

**cURL**

```bash
curl -X GET 'https://www.sendping.co/api/automations/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/runs' \
  -H 'Authorization: Bearer mb_xxxxxxxxx'
```

**CLI**

```bash
sendping automations runs c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd
```

You can filter runs by status (`running`, `completed`, `failed`, `skipped`). Learn how to:

- View run statuses and execution details
- Filter runs by status
- Debug failed runs with step-level error information
- Stop automations when needed

See the [Runs documentation](https://www.sendping.co/docs/automations/runs) and the [List Automation Runs API reference](https://www.sendping.co/docs/api/automations-list-runs) for more details.
