# Create Event

> POST /events — create a custom event definition, optionally with a payload schema.

`POST /events`

Creates a [custom event](https://www.sendping.co/docs/automations/custom-events) definition. If a `schema` is defined, payloads are validated when the event is [sent](https://www.sendping.co/docs/api/events-send) — fields that don't match the expected type are rejected with a `422` error and the event is not delivered.

> **Warning:** This endpoint has two modes, chosen by the body. If the body contains any of `contact_id`, `contactId` or `email`, SendPing treats the request as an alias for [POST /events/send](https://www.sendping.co/docs/api/events-send) and **ingests an event instead of creating a definition** — it then requires an event name — accepted as `event`, `name`, `event_name` or `eventName` — plus `domain`, counts against your automation-run quota, and returns an `event` object with `contact_id` and `enrolled`. The definition-create behaviour documented on this page applies only to bodies with none of those three keys.

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | The name of the custom event. Can be any string (e.g. `user.created`, `welcome`, `my-custom-event`) — dot notation is a recommended convention but is not required. Must not start with the reserved `sendping:` prefix. |
| `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`. |

**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

Returns the created event definition (HTTP 201).

```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"
}
```

Errors: `validation_error` if `name` is missing, uses the reserved prefix, or an event definition with the same name already exists. See [Errors](https://www.sendping.co/docs/api/errors).
