# Send events

> Send a batch of up to 500 analytics events from a game server, with the envelope, every field, deduplication and partial rejection explained.

Sends a batch of events from one game server. This is the endpoint the Luau SDK flushes its queue to, every 10 seconds by default or sooner when the queue reaches the batch size.

The API checks the batch, answers `202 Accepted` straight away and processes the events afterwards. Accepted events usually appear on the **Realtime** page within a few seconds. Authenticate with the project's **write key**; see [Authentication](https://docs.bloxlytics.app/api/authentication).

## Headers

- `Content-Type` (string, header, required): `application/json`.

- `Authorization` (string, header, required): `Bearer ` followed by the project's write key, `bxw_…`. A bridge key is refused.

- `X-Bloxlytics-Project` (string, header, required): The experience's Universe ID, as a decimal string (`game.GameId` in a running server). Legacy UUID project IDs are also accepted.

## Body

The body is one JSON object, at most 1 MB (1,048,576 bytes). Fields not listed here are ignored.

- `protocol` (number, body, required): The wire protocol version. Must be `1`.

- `sdk` (object, body, required): Which client sent the batch. The version is shown as **SDK version** in the project's SDK debugger.  **sdk**
  
  - `name` (string, body, required): Client name, up to 40 characters. The Luau SDK sends `bloxlytics-luau`.
  
  - `version` (string, body, required): Client version, up to 20 characters, for example `1.0.0`.

- `server` (object, body, required): The game server the events come from. Every event in the batch is attributed to this server and place.  **server**
  
  - `jobId` (string, body, required): The server's id, up to 64 characters. The Luau SDK sends `game.JobId`, or `studio-` followed by 8 random hexadecimal characters in Studio, where `game.JobId` is empty. Use the same value for the bridge so commands and presence refer to the same server.
  
  - `placeId` (integer, body, required): The place the server runs (`game.PlaceId`). A whole number, `0` or more.
  
  - `placeVersion` (integer, body): The published place version (`game.PlaceVersion`). A whole number, `0` or more. Stored on the server's record.
  
  - `privateServerId` (string, body): `game.PrivateServerId` for private servers, up to 64 characters. Omit it for public servers. Accepted and validated, but not currently stored.
  
  - `isStudio` (boolean, body): `true` when the batch comes from a Studio session. When a `$server_start` or `$server_heartbeat` arrives with it, the server is marked as a Studio session, which is never chosen automatically for commands.

- `events` (Event[], body, required): Between 1 and 500 events. Each is checked on its own; see [Partial rejection](#partial-rejection). The full rules, including every reserved event, are on [Event format](https://docs.bloxlytics.app/api/ingest/event-format).  **Event**
  
  - `id` (string, body, required): A unique id for this event, 8 to 64 characters. The Luau SDK uses `HttpService:GenerateGUID(false)`. Resending an event with the same `id` is safe: see [Deduplication](#deduplication).
  
  - `name` (string, body, required): The event name, 1 to 64 characters. Either a reserved name starting with `$` (such as `$session_start`) or a custom name: a letter, then letters, digits, spaces and `_ . : -`.
  
  - `ts` (number, body, required): When the event happened, as Unix time in seconds. Fractions are allowed (the SDK sends milliseconds, for example `1767225600.125`). Must be greater than `0`.
  
  - `userId` (integer, body): The Roblox user id of the player the event is about. A positive whole number. Required for every reserved event except the `$server_*` events, and optional for custom events.
  
  - `sessionId` (string, body): The player's session id, up to 64 characters. The SDK creates one per player per server visit and puts it on every event for that player until they leave.
  
  - `props` (object, body): Flat properties: at most 32 keys. Keys start with a letter or `_`, then letters, digits, spaces and `_ . -`, up to 40 characters in all. Values are strings (up to 4,096 characters), finite numbers, booleans or `null`. No nested objects or arrays. An empty array `[]` is read as no properties, because Roblox encodes an empty table that way.

## Response

`202 Accepted` when at least one event passed validation.

- `accepted` (integer, required): How many events passed validation and will be processed.

- `rejected` (integer, required): How many events in the batch failed validation and were discarded. `0` when every event was valid.

`accepted` counts events before the checks that run during processing (below), so a few of them may still be discarded. Duplicates are also counted here and dropped later.

## Validation

The request is checked in this order. The first failure ends it.

1. **Size and JSON.** Over 1 MB: `413`. Not valid JSON: `400`. See [Errors](https://docs.bloxlytics.app/api/errors).
2. **Credentials.** Project header and write key: `401 unauthorized`.
3. **Rate limit.** Over 3,000 batches a minute for the project: `429 rate_limited`.
4. **Envelope.** `protocol`, `sdk`, `server`, and `events` being an array of 1 to 500 items. Any problem: `400 invalid_batch`.
5. **Each event.** Checked against the [event format](https://docs.bloxlytics.app/api/ingest/event-format): `id`, `name`, `ts`, `userId`, `sessionId` and `props`.

### Partial rejection

A bad event doesn't cost you the rest of the batch:

- If **some** events are invalid, the valid ones are accepted and the response is `202` with `rejected` greater than `0`.
- If **every** event is invalid, the response is `400 invalid_batch`, and the message names the first bad event, for example `Rejected batch: events.0.ts (PetHatched) Too small: expected number to be >0`.

Either way, the first problem is recorded under **Recent problems** in the project's SDK debugger, for example `Rejected 2 of 40 events: events.7.ts (Upgrade) Too small: expected number to be >0`.

### Checks during processing

After the batch is accepted, each event goes through checks that depend on your project's settings. Events that fail are discarded and the reason is added to **Recent problems** (up to five distinct reasons per batch), without changing the response you already got.

| Check | Result |
| --- | --- |
| `ts` more than 5 minutes in the future | The event is kept, with its time set to when the batch arrived. |
| `ts` more than 30 days in the past | Discarded: `timestamp older than 30 days`. |
| Reserved event with properties that don't match its definition | Discarded, with the property and problem. |
| Reserved player event without `userId` | Discarded: `<name> requires userId`. |
| Name starting with `$` that isn't a reserved event | Discarded: `Unknown reserved event <name>`. |
| Custom name that doesn't match the naming rule | Discarded: `Invalid event name "<name>"`. |
| Session, economy or purchase tracking turned off | Those events are discarded. |
| Custom events turned off, or the name is in **Blocked events** | Discarded. |
| Economy event in a currency that isn't configured, when currencies are configured | Discarded: `Unknown currency "<currency>" — add it in SDK settings`. |
| Custom-event string value over 256 characters | Kept, with the string cut to 256 characters. |

The settings are on the project's **SDK** page under **Configuration**; see [Project settings](https://docs.bloxlytics.app/projects/settings) and [Remote configuration](https://docs.bloxlytics.app/sdk/remote-config).

## Deduplication

Bloxlytics keeps every event `id` it processes, per project, for 48 hours. An event that arrives again with the same `id` in that time is dropped silently. This makes retries safe: if a request times out and you can't tell whether it arrived, send the same batch again with the same ids.

Give every new event a new id. Reusing an id for a different event within 48 hours loses the second one.

## Batching guidance

- Send events from one server per request: the `server` object applies to every event in the batch.
- The SDK sends at most `maxBatchSize` events per request (200 by default, from 10 to 500 in project settings). Batches with many long string properties can pass 1 MB before they reach the count limit, and a `413` loses the whole batch, so if you write your own client, split batches by encoded size as well as by count.
- Retry `429`, `5xx` and network failures with backoff. Don't retry other `4xx` responses. See [Errors](https://docs.bloxlytics.app/api/errors#what-the-sdk-does).

**Request example**

```bash cURL
curl -X POST https://api.bloxlytics.app/v1/ingest \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer bxw_…" \
  -H "X-Bloxlytics-Project: <universe id>" \
  -d '{
    "protocol": 1,
    "sdk": { "name": "my-client", "version": "1.0.0" },
    "server": { "jobId": "<job id>", "placeId": 1234567890, "placeVersion": 42, "isStudio": false },
    "events": [
      {
        "id": "6F1C2E8C-7B6B-4E0A-9D3F-2A1B5C4D7E9F",
        "name": "$session_start",
        "ts": 1767225600.125,
        "userId": 1,
        "sessionId": "0B7E4D2A-1C3F-4A5B-8D9E-6F7A8B9C0D1E",
        "props": { "username": "<username>", "premium": false, "locale": "en-gb", "country": "GB" }
      },
      {
        "id": "A2B3C4D5-E6F7-4890-A1B2-C3D4E5F60718",
        "name": "PetHatched",
        "ts": 1767225612.5,
        "userId": 1,
        "sessionId": "0B7E4D2A-1C3F-4A5B-8D9E-6F7A8B9C0D1E",
        "props": { "PetName": "Dragon", "Rarity": "Legendary", "EggCost": 500 }
      }
    ]
  }'
```

```json Body
{
  "protocol": 1,
  "sdk": { "name": "bloxlytics-luau", "version": "1.0.0" },
  "server": { "jobId": "<job id>", "placeId": 1234567890, "placeVersion": 42, "isStudio": false },
  "events": [
    {
      "id": "A2B3C4D5-E6F7-4890-A1B2-C3D4E5F60718",
      "name": "PetHatched",
      "ts": 1767225612.5,
      "userId": 1,
      "sessionId": "0B7E4D2A-1C3F-4A5B-8D9E-6F7A8B9C0D1E",
      "props": { "PetName": "Dragon" }
    }
  ]
}
```

**Response example**

```json 202
{ "accepted": 2, "rejected": 0 }
```

```json 202 partial
{ "accepted": 38, "rejected": 2 }
```

```json 400
{
  "error": {
    "code": "invalid_batch",
    "message": "Rejected batch: events.0.id (PetHatched) Too small: expected string to have >=8 characters"
  }
}
```

```json 401
{ "error": { "code": "unauthorized", "message": "Invalid project key." } }
```

```json 413
{ "error": { "code": "FST_ERR_CTP_BODY_TOO_LARGE", "message": "Request body is too large" } }
```

```json 429
{ "error": { "code": "rate_limited", "message": "Too many requests." } }
```
