> ## Documentation Index
> Fetch the complete documentation index at: https://docs.platform.gamezop.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Client-side callbacks for Battles

> Use client-side callbacks to respond to Battle matchmaking, score updates, results, and navigation in your app or website.

Licensed

Battles callbacks let your app or website respond to matchmaking, score updates, match results, and in-game navigation. The `event` field identifies each callback.

> [!NOTE]
>
> Complete the [shared client-side callback setup](https://docs.platform.gamezop.com/publishers/gamezop/guides/client-side-callbacks.md) and [create your Battle game link](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/overview.md#create-a-battle-game-link) before loading the game. Then use this page for the Battles events and their payloads.

## How callbacks work

```mermaid theme={null}
flowchart LR
  game["Battle ends<br/>Final results are calculated<br/>(<b>match_result</b> event is sent)"] --> app["Your Application<br/>Receives each player's final results in real time<br/>(puid, score, rank)"]
  app --> ui["Show the match result screen"]
  app --> analytics["Record the match outcome"]
  app --> custom["Trigger your own action"]

  classDef source fill:#eff6ff,stroke:#3b82f6,color:#1e3a8a;
  classDef receiver fill:#f5f3ff,stroke:#8b5cf6,color:#4c1d95;
  classDef response fill:#f0fdfa,stroke:#14b8a6,color:#134e4a;
  class game source;
  class app receiver;
  class ui,analytics,custom response;
```

> [!NOTE]
>
> Client-side callbacks run on the player's device, so use them for things like updating your UI or recording analytics. When you need a trusted result, for example before giving out rewards, use the [match outcome APIs](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/match-outcomes.md) instead.

***

## Events

A match sends events in this order:

1. `match_found`: players are matched and the countdown starts. If no match is made in time, you get `match_not_found` instead, and no further events.
2. `match_start`: the countdown ends and the match begins.
3. `match_playing`: sent each time any player's score changes, so many times during a match.
4. `match_over`: the player's own game has finished.
5. `match_result`: the match has ended and the final ranking is known.
6. `go_home`: only if the user taps the **Go Home** button.

> [accordion] Match found (match\_found)
>
> **Trigger**
>
> Sent when the player is matched with opponents and the countdown before the match starts.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "event": "match_found",
>   "gameCode": "game-code",
>   "matchId": "match-id",
>   "puids": [
>     "user-123",
>     "user-456"
>   ]
> }
> ```
>
> **Payload notes**
>
> This event lists the matched players in `puids`, rather than in `players`.

> [accordion] No match found (match\_not\_found)
>
> **Trigger**
>
> Sent when the player reaches the end of the wait time (Configurable via the 'maxWait' value in the 'roomDetails' object.) for finding an opponent (Could be more than one opponent, depending on how you configure 'maxPlayers' in the 'roomDetails' object), but the minimum number (Configurable via the 'minPlayers' value in the 'roomDetails' object) of opponents needed to start the match could not be found.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "event": "match_not_found",
>   "gameCode": "game-code"
> }
> ```

> [accordion] Match started (match\_start)
>
> **Trigger**
>
> Sent when the countdown ends and the player starts playing the match.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "event": "match_start",
>   "gameCode": "game-code",
>   "matchId": "match-id",
>   "players": [
>     {
>       "firstName": "Alice",
>       "photo": "https://www.example.com/photos/user-1.png",
>       "puid": "user-123"
>     },
>     {
>       "firstName": "Bob",
>       "photo": "https://www.example.com/photos/user-2.png",
>       "puid": "user-456"
>     }
>   ]
> }
> ```
>
> **Payload notes**
>
> `players` doesn't include `score` or `rank` yet, since the match has only just started.

> [accordion] Match score updated (match\_playing)
>
> **Trigger**
>
> Sent each time any player's score changes. For example, if Alice's score goes from 0 to 1, both Alice and Bob receive `match_playing`.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "event": "match_playing",
>   "gameCode": "game-code",
>   "matchId": "match-id",
>   "players": [
>     {
>       "firstName": "Alice",
>       "photo": "https://www.example.com/photos/user-1.png",
>       "puid": "user-123",
>       "score": 100,
>       "rank": 1
>     },
>     {
>       "firstName": "Bob",
>       "photo": "https://www.example.com/photos/user-2.png",
>       "puid": "user-456",
>       "score": 80,
>       "rank": 2
>     }
>   ]
> }
> ```

> [accordion] Player finished the match (match\_over)
>
> **Trigger**
>
> Sent when a player's game finishes. This happens either when they run out of attempts, or when the match ends while they're still playing because the final ranking can no longer change. Every player receives `match_over` once, before `match_result`.
>
> If the ranking can still change when a player finishes, they see the [waiting screen](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles.md#waiting-for-opponents) until the match ends.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "event": "match_over",
>   "gameCode": "game-code",
>   "matchId": "match-id",
>   "players": [
>     {
>       "firstName": "Alice",
>       "photo": "https://www.example.com/photos/user-1.png",
>       "puid": "user-123",
>       "score": 100,
>       "rank": 1
>     },
>     {
>       "firstName": "Bob",
>       "photo": "https://www.example.com/photos/user-2.png",
>       "puid": "user-456",
>       "score": 80,
>       "rank": 2
>     }
>   ]
> }
> ```

> [accordion] Match results available (match\_result)
>
> **Trigger**
>
> Sent to every player when the match ends, which is as soon as the final ranking can no longer change. This can happen before every player has used their attempts.
>
> For example, Alice and Bob are playing, with Alice on 100 and Bob on 80. Bob runs out of attempts. Alice has already won, so the match ends. Both players get `match_over`, Bob because he ran out of attempts and Alice because her game was stopped, and then both get `match_result`.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "event": "match_result",
>   "gameCode": "game-code",
>   "matchId": "match-id",
>   "players": [
>     {
>       "firstName": "Alice",
>       "photo": "https://www.example.com/photos/user-1.png",
>       "puid": "user-123",
>       "score": 100,
>       "rank": 1
>     },
>     {
>       "firstName": "Bob",
>       "photo": "https://www.example.com/photos/user-2.png",
>       "puid": "user-456",
>       "score": 80,
>       "rank": 2
>     }
>   ]
> }
> ```

> [accordion] Navigate home (go\_home)
>
> **Trigger**
>
> Sent when the user taps the **Go Home** button on the result or "No match found" screen. The button appears when [`text`](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/overview#customise-gameplay-and-the-result-screen) in `roomDetails` is `"go_home"`, which is the default. Use this event to take the user back to your app or website.
>
> If you set `text` to `""`, no button is shown and this event isn't sent. Use `match_result` or `match_not_found` to show your own UI instead.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "event": "go_home",
>   "gameCode": "game-code"
> }
> ```

***

## Payload fields

Depending on the platform, your callback handler receives each payload as an object or a JSON string. The examples above show the decoded JSON. Not every field appears in every event, so ignore any fields you don't recognise instead of rejecting the payload.

| Field | Type | Meaning |
| - | - | - |
| `event` | String | The event name, such as `match_start`. |
| `gameCode` | String | The game's identifier; corresponds to `code` in the [All Games API](https://docs.platform.gamezop.com/publishers/gamezop/guides/all-games-api.md). |
| `matchId` | String | The match's identifier. If you've built the [Create Match API](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/match-outcomes.md#create-match-api), this is the `match_id` your server returned. Otherwise, Gamezop generates it. Sent in every event except `match_not_found` and `go_home`. |
| `puids` | Array of strings | In `match_found` only: the `puid` of every player matched together. |
| `players` | Array of objects | One object per player in the match, with the fields below. |
| `players[].firstName` | String | The `user.name` you passed in [`roomDetails`](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/overview#identify-your-players). |
| `players[].photo` | String | The `user.photo` you passed in `roomDetails`. |
| `players[].puid` | String | The `user.puid` you passed in `roomDetails`. For a bot, it's the `puid` you set in `roomDetails.bots`, or one Gamezop created if you didn't set one. |
| `players[].score` | Number | The player's latest score. Not sent in `match_start`. |
| `players[].rank` | Number | The player's latest rank in the match. Players with the same score share a rank: for example, scores of 100, 100, and 80 give ranks 1, 1, and 3. Not sent in `match_start`. |

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.