# Send Event

> POST /events/send — send a custom event to trigger automations for a contact.

`POST /events/send`

Records a custom event for a contact and immediately enrolls that contact into every **enabled** [automation](https://www.mailblastr.com/docs/automations/overview) **belonging to the given `domain`** whose trigger matches the event name. `domain` is required — every automation belongs to one of your sending domains, so the same event name (e.g. `user.created`) used across several products can never trigger another product's automations. The contact is identified by `contact_id` or `email` — you must supply exactly one. If an email is supplied and no matching contact exists in that domain's contacts, one is created automatically when the run starts; each domain keeps its own contact records, so unsubscribe state stays separate per domain.

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `event` | string | Yes | The custom event name. Must not start with the reserved `mailblastr:` prefix. |
| `domain` | string | Yes | The sending domain this event belongs to (one of your domains, e.g. `yourdomain.com`). Only automations belonging to this domain are triggered. |
| `contact_id` | string | No | Identify the contact by id. Provide `contact_id` OR `email`. |
| `email` | string | No | Identify the contact by email address. Provide `contact_id` OR `email`. If no contact with this address exists in the domain's contacts, one is created when the run starts. |
| `payload` | object | No | Optional. Arbitrary key-value data associated with the event. Must be an object (not an array). Fields become available as `event.*` variables in automation steps. |

> **Warning:** If an [event definition](https://www.mailblastr.com/docs/api/events-create) with a schema exists for this event name, the payload is validated against it — fields that don't match the expected type are rejected with a `422` error and the event is not delivered.

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

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

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Events.send({
  "event": "purchase.completed",
  "domain": "yourdomain.com",
  "email": "user@example.com",
  "payload": {
    "plan": "pro",
    "amount": 49
  }
})
```

**PHP**

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

$mailblastr->events->send([
  'event' => "purchase.completed",
  'domain' => "yourdomain.com",
  'email' => "user@example.com",
  'payload' => [
    'plan' => "pro",
    'amount' => 49
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Events.send({
  "event": "purchase.completed",
  "domain": "yourdomain.com",
  "email": "user@example.com",
  "payload": {
    "plan": "pro",
    "amount": 49
  }
})
```

**Go**

```go
client := mailblastr.NewClient("mb_xxxxxxxxx")

params := &mailblastr.SendEventRequest{
    Name:   "signup.completed",
    Domain: "yourdomain.com",
    Email:  "jane@example.com",
}
event, err := client.Events.Send(params)
```

**Rust**

```rust
let mb = Mailblastr::new("mb_xxxxxxxxx");

let event = SendEventOptions::new("signup.completed", "yourdomain.com")
    .with_email("jane@example.com");
let _sent = mb.events.send(event).await?;
```

**Java**

```java
Mailblastr mailblastr = new Mailblastr("mb_xxxxxxxxx");

SendEventRequest request = SendEventRequest.builder()
    .name("signup.completed")
    .domain("yourdomain.com")
    .email("jane@example.com")
    .build();
mailblastr.events().send(request);
```

**.NET**

```csharp
IMailblastr mailblastr = MailblastrClient.Create("mb_xxxxxxxxx");

var resp = await mailblastr.EventSendAsync(new EventSendOptions
{
    Name = "signup.completed",
    Domain = "yourdomain.com",
    Email = "jane@example.com",
});
```

**cURL**

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

### Response

```json
{
  "object": "event",
  "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
  "event": "purchase.completed",
  "contact_id": "e169aa45-1ecf-4183-9955-b1499d5701d3",
  "enrolled": 1
}
```

`enrolled` is the number of automations the contact was enrolled into as a result of this event. Errors: `validation_error` if `event` or `domain` is missing, the domain is not one of yours, or the event name uses the reserved prefix; `422` if the payload does not match the event definition's schema. See [Errors](https://www.mailblastr.com/docs/api/errors).
