# Send an event

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

Sends one event to rooms, to users (every tab and device they have open), or both. Everyone in a room gets it,
and a room whose `history` you give keeps it for pages that reconnect.

The data is any JSON, up to 1 MB. Seal it first to keep it from WordPlus Cloud ([sealing](/api/sealing/)):
the packages seal the data of every room and user by default.

In the packages: `realtime.to( rooms ).toUser( users ).emit( event, data )`.

## Request

```json
{
  "rooms": [
    "order:42"
  ],
  "event": "updated",
  "data": {
    "status": "shipped"
  },
  "history": {
    "order:42": [
      20,
      0.003472222222222222
    ]
  }
}
```

## Answer

Sent. The ids of the events kept, by room.

```json
{
  "ok": true,
  "ids": {
    "order:42": "1791638400000-0"
  }
}
```

## 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 '{"rooms":["order:42"],"event":"updated","data":{"status":"shipped"}}'
```

**Node**

```js
const { ids } = await wordplus('POST', '/wordplus/realtime/emit', { rooms: ['order:42'], event: 'updated', data: { status: 'shipped' } });
```

**Python**

```python
answer = wordplus("POST", "/wordplus/realtime/emit", {"rooms": ["order:42"], "event": "updated", "data": {"status": "shipped"}})
```

**PHP**

```php
$answer = wordplus('POST', '/wordplus/realtime/emit', ['rooms' => ['order:42'], 'event' => 'updated', 'data' => ['status' => 'shipped']]);
```

**Go**

```go
answer, err := app.Request("POST", "/wordplus/realtime/emit", map[string]any{"rooms": []string{"order:42"}, "event": "updated", "data": map[string]any{"status": "shipped"}})
```

