`lumail@2.1.0` · [`lumail.events`](/docs/sdk/v2/events)

```typescript
events.create(params: CreateEventParams): Promise<LumailResult<CreateEventResponse>>
```

`eventType` is `SUBSCRIBER_PAYMENT` or `SUBSCRIBER_REFUND`. `subscriber` is an email or id.

## Body Parameters

| Name | Type | Description |
| ------------ | --------------------- | ---------------------------------------------------------------- |
| `eventType` | `SubscriberEventType` | **Required.** Use `SUBSCRIBER_PAYMENT` or `SUBSCRIBER_REFUND`. |
| `subscriber` | string | **Required.** Subscriber email or id. |
| `data` | `Record` | **Required.** Event payload. Typical keys: `amount`, `currency`. |

## Response Fields

| Field | Type | Description |
| ---------------- | --------------------- | ---------------------------- |
| `id` | string | Created event id. |
| `eventType` | `SubscriberEventType` | Stored type. |
| `data` | `Record` | Optional stored payload. |
| `subscriberId` | string | Optional subscriber id. |
| `organizationId` | string | Optional organization id. |
| `createdAt` | string | Optional ISO 8601 timestamp. |

HTTP maps to `{ id, eventType }`. `data` is that object. Failures return `{ data: null, error: { name, message, statusCode } }`.


## API Reference
**Method:** POST
**Endpoint:** /api/v2/events

### SDK
```ts
import { Lumail } from "lumail";

const lumail = new Lumail({ apiKey: process.env.LUMAIL_API_KEY });
const { data, error } = await lumail.events.create({
  eventType: "SUBSCRIBER_PAYMENT",
  subscriber: "user@example.com",
  data: { amount: 2000, currency: "usd" },
});
if (error) {
  throw error;
}
console.log(data.id, data.eventType);
```

### cURL
```bash
curl -X POST https://lumail.io/api/v2/events \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"eventType":"SUBSCRIBER_PAYMENT","subscriber":"user@example.com","data":{"amount":2000,"currency":"usd"}}'
```

### JavaScript
```javascript
const response = await fetch("https://lumail.io/api/v2/events", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    eventType: "SUBSCRIBER_PAYMENT",
    subscriber: "user@example.com",
    data: { amount: 2000, currency: "usd" },
  }),
});
const data = await response.json();
```

### Success Response
```json
{
  "id": "evt_abc123",
  "eventType": "SUBSCRIBER_PAYMENT"
}
```

### Error Response
```json
{
  "name": "validation_error",
  "message": "eventType must be SUBSCRIBER_PAYMENT or SUBSCRIBER_REFUND",
  "statusCode": 422
}
```
