---
title: "client.events"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/ruby/reference/events"
area: "Ruby"
category: "Reference"
---

# client.events

Every method in this namespace: its signature, its parameters, what it returns and an example.

## Methods

Things your contacts did, sent by your own code, such as an order placed or a trial started. An event starts the automations whose trigger names it and ends the waits that were holding out for it.

### `events.send`

Record that something happened to a contact

```ruby
send(body = nil, idempotency_key: nil, api_key: nil, **fields) -> Hash
```

Records an event against one contact, named by `email` or `contactId`: an order placed, a trial started, a plan changed. Every live automation whose trigger is this event name, and whose filters match `properties`, takes the contact in, and any wait step holding out for the name moves on. `enrolled` and `resumed` in the answer say what it set off. Events are kept for 90 days.

Every call carries an `Idempotency-Key`. The SDK generates one per call and reuses it on that call's retries, so a retried network failure returns the stored event instead of recording a second one. Pass `idempotency_key:` to extend that across processes and restarts. A replay returns the stored event with `replayed` set to true and starts nothing again. The same key with a different event is a 422 `idempotency_key_reuse`.

An event sent with a test key is stored with `mode` `test` and starts or resumes nothing.

Scopes: `contacts:write`.

**Parameters**

- `name` (`String`, required): What happened, such as `order.placed`: 1 to 100 letters, digits, dots, colons, dashes and underscores, starting with a letter or a digit. Names are matched exactly, case included.
- `email` (`String`): The contact the event is about, by email address. Send this or `contactId`.
- `contactId` (`String`): The contact the event is about, by id. Send this or `email`.
- `properties` (`Hash`): Anything worth keeping about the event, as a Hash of at most 50 keys and 4 KB of JSON. An event trigger can filter on these, and steps can put them in an email or a contact field.
- `occurredAt` (`Time, Date or String`): When it happened, as a `Time` or an ISO 8601 string. Left out, it is now. It cannot be in the future or more than 90 days ago.
- `createContact` (`Boolean`): Add the address to the contacts when nobody has it yet. It needs `email`. Left out or false, an unknown address is a 404 `contact_not_found`.
- `contactName` (`String`): The name to give a contact that `createContact` adds, at most 200 characters.
- `idempotency_key` (`String`): Your own key, 1 to 255 characters of letters, digits, `_`, `.`, `:` or `-`. Anything else is a 400 `invalid_idempotency_key`.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash, the event, with `id`, `contactId`, `email`, `name`, `properties`, `occurredAt`, `mode` and `createdAt`, plus `replayed`, `enrolled`, the ids of the automations it put the contact into, and `resumed`, how many waits it ended.

**Example**

```ruby
event = client.events.send(
  name: "order.placed",
  email: "ada@example.com",
  properties: {orderId: "AC-4192", total: 129},
  createContact: true,
  idempotency_key: "order:AC-4192:placed"
)

p event.values_at(:id, :enrolled, :resumed, :replayed)
```

**Notes**

- A name, properties or an `occurredAt` that break a rule, or a body that names no contact, is 422 `invalid_event` with `param` naming the field.
- A key or an app may send 600 events a minute. Past that the call is 429 `event_rate_limited`.
- An app a member connected reaches only the contacts that member added, and a contact it creates belongs to that member.
- Retried automatically on network failure and retryable statuses, because the idempotency key makes a retry safe.

Also available in: API [`POST /events`](https://openemail.uk/docs/api/reference/events#post-events); TypeScript [`events.send()`](https://openemail.uk/docs/sdk/reference/events#send); Python [`events.send()`](https://openemail.uk/docs/python/reference/events#send); PHP [`events->send`](https://openemail.uk/docs/php/reference/events#send); Go [`Events.Send`](https://openemail.uk/docs/go/reference/events#send); Java [`events().send`](https://openemail.uk/docs/java/reference/events#send); C# [`Events.SendAsync`](https://openemail.uk/docs/csharp/reference/events#send); CLI [`openemail events send`](https://openemail.uk/docs/cli/reference/events#events-send).

### `events.send_batch`

Record up to 100 contact events in one call

```ruby
send_batch(events, idempotency_key: nil, api_key: nil) -> Hash
```

Records each event in order, as if `events.send` had been called for it, and reports per event. It is never all or nothing: `accepted` holds the events that were stored and `failed` the ones that were not, each with the `index` it had in the Array, so one unknown address does not stop the rest. The call returns whenever the batch was processed, so check `failed` rather than relying on a raise.

The batch shares one `Idempotency-Key`, generated once per call or supplied as `idempotency_key:`, and the server remembers each event under the key and its position. Retrying the same Array replays the events that were already stored and records only the ones that were not. Reordering the Array between attempts makes an event that moved fail with `idempotency_key_reuse`.

Scopes: `contacts:write`.

**Parameters**

- `events` (`Array<Hash>`, required): The events, 1 to 100 of them, each in the shape `events.send` takes: `name`, `email` or `contactId`, and optionally `properties`, `occurredAt`, `createContact` and `contactName`.
- `idempotency_key` (`String`): Your own key for the whole batch, 1 to 255 characters of letters, digits, `_`, `.`, `:` or `-`.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `accepted`, each a Hash shaped like the result of `send` plus its `index`, and `failed`, each a Hash with `index`, `code` and `message`.

**Example**

```ruby
events = [
  {name: "trial.started", email: "ada@example.com"},
  {name: "trial.started", email: "grace@example.com", properties: {plan: "team"}}
]

batch = client.events.send_batch(events, idempotency_key: "trials:2026-10-11")

batch[:failed].each { |failure| warn "#{failure[:index]} #{failure[:code]} #{failure[:message]}" }

puts batch[:accepted].size
```

**Notes**

- A body of the wrong shape, an empty Array or more than 100 events is refused whole with 422 `invalid_parameter`, and `param` names the event and the field, such as `events.3.name`.
- The batch counts as that many events toward the 600 a minute a key or an app may send. A batch that would pass it is 429 `event_rate_limited` and nothing is stored.
- A failed event carries the code the single call would answer: `invalid_event`, `contact_not_found` or `idempotency_key_reuse`.
- Retried automatically on network failure and retryable statuses, because the idempotency key makes a retry safe.

Also available in: API [`POST /events/batch`](https://openemail.uk/docs/api/reference/events#post-events-batch); TypeScript [`events.sendBatch()`](https://openemail.uk/docs/sdk/reference/events#sendBatch); Python [`events.send_batch()`](https://openemail.uk/docs/python/reference/events#sendBatch); PHP [`events->sendBatch`](https://openemail.uk/docs/php/reference/events#sendBatch); Go [`Events.SendBatch`](https://openemail.uk/docs/go/reference/events#sendBatch); Java [`events().sendBatch`](https://openemail.uk/docs/java/reference/events#sendBatch); C# [`Events.SendBatchAsync`](https://openemail.uk/docs/csharp/reference/events#sendBatch); CLI [`openemail events send-batch`](https://openemail.uk/docs/cli/reference/events#events-send-batch).

### `events.list_names`

List the event names the workspace has seen

```ruby
list_names(api_key: nil) -> Array<Hash>
```

Returns the distinct names of the events the workspace holds, in byte order, at most 100. It is what the app suggests when somebody picks the event that starts an automation. Events are kept for 90 days, so a name nothing has sent in that time is gone. The list is not paginated.

Scopes: `automations:read`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

An Array of Hashes, each with `name`.

**Example**

```ruby
names = client.events.list_names

p names.map { |entry| entry[:name] }
```

**Notes**

- It needs `automations:read`, not a contacts scope, because it serves the automation builder.
- Read only, so the SDK retries it after a network failure like any other read.

Also available in: API [`GET /events/names`](https://openemail.uk/docs/api/reference/events#get-events-names); TypeScript [`events.listNames()`](https://openemail.uk/docs/sdk/reference/events#listNames); Python [`events.list_names()`](https://openemail.uk/docs/python/reference/events#listNames); PHP [`events->listNames`](https://openemail.uk/docs/php/reference/events#listNames); Go [`Events.ListNames`](https://openemail.uk/docs/go/reference/events#listNames); Java [`events().listNames`](https://openemail.uk/docs/java/reference/events#listNames); C# [`Events.ListNamesAsync`](https://openemail.uk/docs/csharp/reference/events#listNames); CLI [`openemail events list-names`](https://openemail.uk/docs/cli/reference/events#events-list-names).
