# Send events in a batch

`POST https://rest.wordplus.cloud/wordplus/realtime/emit/batch`

Sends up to 100 events in one request, each as Send an event takes it. The answer
has the kept ids of each, in their order.

In the packages: `realtime.batch( events )`.

## Request

```json
{
  "events": [
    {
      "rooms": [
        "product:7"
      ],
      "event": "price",
      "data": {
        "price": 12
      }
    },
    {
      "users": [
        "42"
      ],
      "event": "notice",
      "data": {
        "text": "Price changed"
      }
    }
  ]
}
```

## Answer

Sent. The ids of the events kept, by room, for each event in its order.

```json
{
  "ok": true,
  "ids": [
    {},
    {}
  ]
}
```

## Refusals

- **400**: `bad_request`, `bad_room`: the request is not one the API takes. `reserved`: an event name kept for the room itself.
- **401**: `missing_signature`, `stale_signature` (a clock off by more than 5 minutes), `unknown_site`, `bad_signature` (a wrong secret, or a body or path other than the one signed).
- **403**: `not_included`: your plan does not include it.
- **413**: `too_large`: data over 1 MB. `too_many`: over 1,000 rooms or users in an event, or 100 events in a batch.

## Examples

`wordplus()` (in Go `app.Request()`) signs and sends the request: https://docs.wordplus.cloud/api/signing/ has it in each language.

**curl**

```bash
wordplus POST /wordplus/realtime/emit/batch '{"events":[{"rooms":["product:7"],"event":"price","data":{"price":12}},{"users":["42"],"event":"notice","data":{"text":"Price changed"}}]}'
```

**Node**

```js
await wordplus('POST', '/wordplus/realtime/emit/batch', { events: [
    { rooms: ['product:7'], event: 'price', data: { price: 12 } },
    { users: ['42'], event: 'notice', data: { text: 'Price changed' } },
] });
```

**Python**

```python
wordplus("POST", "/wordplus/realtime/emit/batch", {"events": [
    {"rooms": ["product:7"], "event": "price", "data": {"price": 12}},
    {"users": ["42"], "event": "notice", "data": {"text": "Price changed"}},
]})
```

**PHP**

```php
wordplus('POST', '/wordplus/realtime/emit/batch', ['events' => [
    ['rooms' => ['product:7'], 'event' => 'price', 'data' => ['price' => 12]],
    ['users' => ['42'], 'event' => 'notice', 'data' => ['text' => 'Price changed']],
]]);
```

**Go**

```go
answer, err := app.Request("POST", "/wordplus/realtime/emit/batch", map[string]any{"events": []any{
    map[string]any{"rooms": []string{"product:7"}, "event": "price", "data": map[string]any{"price": 12}},
    map[string]any{"users": []string{"42"}, "event": "notice", "data": map[string]any{"text": "Price changed"}},
}})
```

