# Connections

> Connections between steps in automation workflows.

## How it works

Connections are the code definitions for the links between [steps](https://www.sendping.co/docs/automations/steps) in the automation graph and are defined and retrieved using the API.

If creating an automation via the API, define connections as an array of objects.

**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" }
  ]
}'
```

When retrieving automations, the API returns the connections as an array.

**Response**

```json
{
  "object": "automation",
  "id": "c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd",
  "audience_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf",
  "domain": "yourdomain.com",
  "name": "Welcome series",
  "trigger": "user.created",
  "status": "disabled",
  "created_at": "2026-10-01T12:00:00.000Z",
  "updated_at": "2026-10-01T12:00:00.000Z",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "id": "9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d",
      "key": "welcome",
      "type": "send_email",
      "position": 0,
      "config": {
        "template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" }
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "welcome",
      "type": "default"
    }
  ]
}
```

> **Note:** Connections must form an acyclic graph — cyclic graphs are rejected. Editing connections requires the automation to be **disabled**.

## Connection properties

Connections define the links between steps in the automation graph.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | string | Yes | This is the `key` of the origin step. |
| `to` | string | Yes | This is the `key` of the destination step. |
| `type` | string | No | The type of connection between the origin and destination steps. Most automations use the default connection type. Use a non-default `type` only when the origin step can branch to multiple destinations: for [wait_for_event](https://www.sendping.co/docs/automations/wait-for-event), use `event_received` or `timeout`; for [condition](https://www.sendping.co/docs/automations/condition), use `condition_met` or `condition_not_met`. Possible values: `default`, `condition_met`, `condition_not_met`, `timeout`, `event_received`. |

**Example**

```json
{
  "from": "start",
  "to": "welcome",
  "type": "default"
}
```
