# Poll for commands

> Report a server's players and long-poll for queued Cmdr, kick, warn and announce commands, held open for up to 20 seconds.

A long poll. The game server reports who is in it and waits for commands. If commands are waiting, they're returned at once; otherwise the request is held open for up to 20 seconds and returns as soon as a command arrives, or empty when the time is up. Then the server polls again.

Game servers never accept incoming connections, so this is how Bloxlytics reaches them: every command a team member runs from the dashboard is picked up by a poll. Polling also keeps the server listed as online, with an up-to-date player list.

Call [hello](https://docs.bloxlytics.app/api/bridge/hello) first, and stop polling if it returned `enabled: false`. Authentication and replay headers are the same as for every bridge endpoint; see [Authentication](https://docs.bloxlytics.app/api/authentication#replay-protection-for-the-bridge).

## Headers

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

- `Authorization` (string, header, required): `Bearer ` followed by the project's bridge key, `bxb_…`.

- `X-Bloxlytics-Project` (string, header, required): The experience's Universe ID (`game.GameId`).

- `X-Bloxlytics-Timestamp` (string, header, required): The current Unix time in seconds, within 120 seconds of Bloxlytics' clock.

- `X-Bloxlytics-Nonce` (string, header, required): A new random value for this request, 16 to 64 characters from `A–Z a–z 0–9 - { }`.

## Body

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

- `jobId` (string, body, required): The server's id, up to 64 characters. The same value you sent to hello.

- `placeId` (integer, body, required): `game.PlaceId`. A whole number, `0` or more.

- `players` (integer[], body, default []): The Roblox user ids of everyone in the server right now, up to 700, each a positive whole number. Replaces the list from the last poll. Bloxlytics uses it to show who is where and to route commands to the server a player is in.

- `tags` (object, body): The server's current tags, such as `{ "map": "Forest" }`: up to 16, names starting with a letter then letters, digits, spaces, `_ . -` (up to 32 characters), values up to 64 characters. Omit to keep the tags already known.

- `studio` (boolean, body): `true` for a Studio session.

## Response

`200 OK` with the commands for this server. At most 10 commands come back per poll: first those addressed to this server, and only when there are none of those, commands that any server may run. Bloxlytics normally addresses every command to one server when it's queued.

- `commands` (Command[], required): The commands to run, in the order they were queued. `[]` when the hold time ran out with nothing to do.  **Command**
  
  - `id` (string, required): The execution id. Report the outcome under this id with [result](https://docs.bloxlytics.app/api/bridge/result), once.
  
  - `kind` (string, required): `cmdr`, `kick`, `warn` or `announce`.
  
  - `text` (string): For `cmdr`: the full Cmdr command line, for example `give "<username>" 500`. Run it through Cmdr's own dispatcher so its type checks and `BeforeRun` hooks apply.
  
  - `userId` (integer): For `kick` and `warn`: the Roblox user id of the target player.
  
  - `message` (string): For `kick`, `warn` and `announce`: the text to show. May be absent.
  
  - `expiresAt` (integer, required): Unix time in seconds after which the command must not run: 60 seconds after it was queued. Refuse commands past this time.
  
  - `issuedBy` (object, required): The team member who sent the command. The Luau bridge passes these to Cmdr as `context.Data.Bloxlytics` (`Id`, `Name`, `Role`).  **issuedBy**
    
    - `id` (string, required): Their Bloxlytics user id.
    
    - `name` (string, required): Their name in Bloxlytics.
    
    - `role` (string, required): Their role in the workspace, for example `owner`, `admin` or `developer`.
  
  - `executorUserId` (integer): Only on `cmdr` commands, and only when the issuer has linked and verified their Roblox account **and** that player is in this server. Run the command as that player, so the game's own permission hooks judge them exactly as if they had typed it.

`204 No Content` is returned instead if the caller closed the connection while the poll was held. A client doesn't normally see it; treat it like an empty poll.

## Timing

- **Hold time.** Up to 20 seconds (`pollHoldSeconds` from hello). While a poll is held, Bloxlytics checks for new commands about every 0.4 seconds, so a command reaches a polling server well under a second after it's queued.
- **Client timeout.** Give the request more than 20 seconds, ideally 25 or more, so a normal empty return isn't cut off.
- **Next poll.** Poll again straight away after each response, after reporting any results. On a failure, back off: the Luau bridge waits 2 seconds, doubling up to 60.
- **Online status.** Each poll counts as the server being seen. A server that hasn't polled or sent an analytics heartbeat for 90 seconds is no longer shown as online, and commands aren't sent to it.
- **Rate limit.** 20,000 polls a minute per project. A server polling continuously uses about three a minute when idle.

## Delivery guarantees

- A command is delivered to **one** poll. Once returned, it's marked as dispatched to this `jobId`, and only this server's result is accepted for it.
- A command that's past `expiresAt` when a poll picks it up is not delivered: it's marked as timed out (`Expired before a server picked it up.`).
- If the poll response is lost on the way (for example the connection drops), the command isn't sent again. It's marked as timed out if no result arrives.

## What the server must do

The bridge never runs anything except registered commands, through the game's own code. For every command in the response:

1. **Skip duplicates.** Keep the ids you've run (the Luau bridge keeps them for 10 minutes) and report an id you've already seen as failed, without running it again.
2. **Check `expiresAt`** against `os.time()`. If it has passed, don't run it; report it as failed.
3. **Run it.** `cmdr`: through Cmdr's dispatcher, as the `executorUserId` player if given, otherwise in the system context (or refuse, if the server doesn't allow system commands). `kick`, `warn`, `announce`: only if the server enabled that capability.
4. **Report** every outcome in one [result](https://docs.bloxlytics.app/api/bridge/result) request.

See [Cmdr bridge security](https://docs.bloxlytics.app/sdk/cmdr-bridge/security) for the full model.

**Request example**

```bash cURL
curl -X POST https://api.bloxlytics.app/v1/bridge/poll \
  --max-time 30 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer bxb_…" \
  -H "X-Bloxlytics-Project: <universe id>" \
  -H "X-Bloxlytics-Timestamp: $(date +%s)" \
  -H "X-Bloxlytics-Nonce: $(uuidgen)" \
  -d '{
    "protocol": 1,
    "jobId": "<job id>",
    "placeId": 1234567890,
    "players": [1, 2, 3],
    "tags": { "map": "Forest" },
    "studio": false
  }'
```

**Response example**

```json 200
{
  "commands": [
    {
      "id": "<execution id>",
      "kind": "cmdr",
      "text": "give \"<username>\" 500",
      "expiresAt": 1767225660,
      "issuedBy": { "id": "<user id>", "name": "<name>", "role": "admin" },
      "executorUserId": 1
    },
    {
      "id": "<execution id>",
      "kind": "kick",
      "userId": 2,
      "message": "You were removed from the server.",
      "expiresAt": 1767225662,
      "issuedBy": { "id": "<user id>", "name": "<name>", "role": "owner" }
    }
  ]
}
```

```json 200 empty
{ "commands": [] }
```

```json 400
{ "error": { "code": "invalid_payload", "message": "players.0: Too small: expected number to be >0" } }
```

```json 401
{ "error": { "code": "bad_nonce", "message": "Missing nonce." } }
```
