# Custom Events

> Define custom events to trigger automations.

Custom events are used to [trigger](https://www.sendping.co/docs/automations/trigger) automations and can be defined with an optional schema for payload validation.

If a schema is defined, payloads are validated when the event is sent. Fields that don't match the expected type are rejected with a `422` error and the event is not delivered.

## How it works

In the dashboard, the **Events** page shows all existing events. Click **Add event**, enter the event name and an optional schema to define the event payload you will send with the event, then **Save**.

Over the API, all existing events can be retrieved with the [List Events API](https://www.sendping.co/docs/api/events-list). To create a new event, use the [Create Event API](https://www.sendping.co/docs/api/events-create).

**Node.js**

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

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.events.create({
  "name": "user.created",
  "schema": {
    "plan": "string"
  }
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Events.create({
  "name": "user.created",
  "schema": {
    "plan": "string"
  }
})
```

**PHP**

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

use SendPing\SendPing;

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

$sendping->events->create([
  'name' => "user.created",
  'schema' => [
    'plan' => "string"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Events.create({
  "name": "user.created",
  "schema": {
    "plan": "string"
  }
})
```

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

definition, err := client.Events.Create(&sendping.CreateEventRequest{
    Name:   "user.created",
    Schema: map[string]string{"plan": "string"},
})
```

**Rust**

```rust
use sendping::{CreateEventOptions, EventFieldType, SendPing};

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

let params = CreateEventOptions::new("user.created")
    .with_schema_field("plan", EventFieldType::String);
let _definition = mb.events.create(params).await?;
```

**Java**

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

SendPing sendping = new SendPing("mb_xxxxxxxxx");

CreateEventRequest request = CreateEventRequest.builder()
        .name("user.created")
        .schema("plan", "string")
        .build();

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

**.NET**

```csharp
using SendPing;

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

var resp = await sendping.EventCreateAsync(new EventCreateOptions
{
    Name = "user.created",
    Schema = new Dictionary<string, string> { ["plan"] = "string" },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/events' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "user.created",
  "schema": {
    "plan": "string"
  }
}'
```

**CLI**

```bash
sendping events create \
  --name 'user.created' \
  --schema '{"plan":"string"}'
```

**Response**

```json
{
  "object": "event",
  "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
  "name": "user.created",
  "schema": {
    "plan": "string"
  },
  "created_at": "2026-06-23T10:00:00.000Z",
  "updated_at": "2026-06-23T10:00:00.000Z"
}
```

> **Note:** The event name can be any string (e.g. `user.created`, `welcome`, `my-custom-event`). Dot notation is a recommended convention but is not required. If multiple enabled automations use the same event name, **all** of them will be triggered.

## Sending events

Trigger your automations by sending an event with [`POST /events/send`](https://www.sendping.co/docs/api/events-send). Name the `domain` the event belongs to (only that domain's automations fire), identify the contact by `contact_id` or `email`, and optionally attach a `payload` object — its fields become available as `event.*` variables in templates, [conditions](https://www.sendping.co/docs/automations/condition), and other steps. See [Trigger](https://www.sendping.co/docs/automations/trigger) for details.

**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": "479e3145-dd38-476b-932c-529ceb705947",
  "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": "479e3145-dd38-476b-932c-529ceb705947",
  "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' => "479e3145-dd38-476b-932c-529ceb705947",
  'payload' => [
    'plan' => "pro"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Events.send({
  "event": "user.created",
  "domain": "yourdomain.com",
  "contact_id": "479e3145-dd38-476b-932c-529ceb705947",
  "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: "479e3145-dd38-476b-932c-529ceb705947",
    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("479e3145-dd38-476b-932c-529ceb705947")
    .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("479e3145-dd38-476b-932c-529ceb705947")
        .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 = "479e3145-dd38-476b-932c-529ceb705947",
    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": "479e3145-dd38-476b-932c-529ceb705947",
  "payload": {
    "plan": "pro"
  }
}'
```

**CLI**

```bash
sendping events send \
  --name 'user.created' \
  --domain 'yourdomain.com' \
  --contact-id '479e3145-dd38-476b-932c-529ceb705947' \
  --data '{"plan":"pro"}'
```

## Configuration

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | The name of the custom event to create. Used to match events to automation triggers. Cannot start with the `sendping:` prefix, which is reserved for system events. |
| `schema` | object | No | An optional schema definition for the event payload. Must be an object with flat key/type pairs. Supported types: `string`, `number`, `boolean`, `date`. |

**Example**

```json
{
  "schema": {
    "plan": "string",
    "amount": "number",
    "date": "date",
    "is_active": "boolean"
  }
}
```

> **Warning:** Event names cannot start with the `sendping:` prefix, which is reserved for system events. Creating a definition with a name that already exists returns a `validation_error`.
