> ## 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.

# Integrate Battles

> Set up Battles and create game links that match your users in real time.

Licensed

> [!NOTE]
>
> Battles are only available with the licensed model. [Contact us](https://business.gamezop.com/contact-us/enquire-now) to know more.

> [!NOTE]
>
> Battles are real-time matches between 2 to 5 players. If you instead want to run time-bound competitions with a leaderboard, open to all your users, see [Tournaments](https://docs.platform.gamezop.com/publishers/gamezop/offerings/tournaments.md).

## Set up your Battles integration

**1. Enable your games and Battles**

Select the games you want to use, along with your Gamezop Account Manager. They enable those games and Battles for your [Property ID](https://docs.platform.gamezop.com/publishers/get-started/key-terms.md#property-or-property-id).

**2. Create Battle game links**

Add a `roomDetails` parameter to each game URL so that Gamezop can match your users. See [Create a Battle game link](#create-a-battle-game-link) below.

**3. Set up client-side callbacks (optional)**

To receive Battle events in your app or website, ask your Gamezop Account Manager to enable client-side callbacks, then follow [Client-side callbacks for Battles](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/client-side-callbacks.md).

**4. Receive match results on your server (optional)**

To save Battle results or reward players from your backend, set up the [match outcome APIs](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/match-outcomes.md).

**5. Add bots (optional)**

To match users with bots when no opponent is found, see the [bot fields](#add-bot-opponents) below.

***

## Create a Battle game link

A game `url` from the [All Games API](https://docs.platform.gamezop.com/publishers/gamezop/guides/all-games-api.md) opens a single-player game by default. To open it as a Battle, add a `roomDetails` parameter to the URL.

**1. Create a "roomDetails" object**

The `roomDetails` object tells Gamezop which users to match together. **`roomId` is the only required field; all other fields are optional.**

Users who open a game with the same `roomId` are matched together. You can use a different `roomId` for each group, skill level, or other matchmaking pool.

```json theme={null}
{
  "roomId": "ABC01"
}
```

To customise the match, add any of the [optional fields](#optional-roomdetails-fields) before you encode the object.

**2. Encode the "roomDetails" object**

Convert the object to JSON, Base64 encode it, then URL encode the result. In JavaScript:

```javascript theme={null}
// roomDetails is the object from the previous step.
const bytes = new TextEncoder().encode(JSON.stringify(roomDetails));
const base64 = btoa(Array.from(bytes, byte => String.fromCharCode(byte)).join(''));
const encoded = encodeURIComponent(base64);
```

For the example above, `encoded` is:

```wrap theme={null}
eyJyb29tSWQiOiJBQkMwMSJ9
```

**3. Add it to the game URL**

Add the encoded value to the game's `url` as the `roomDetails` query parameter:

```wrap theme={null}
https://3025.play.gamezop.com/g/NyM_JGWcx?roomDetails=eyJyb29tSWQiOiJBQkMwMSJ9
```

If you pass player details or use different `roomId` values, build the link separately for each user. If all your users share the same `roomDetails`, you can create one link and send everyone to it.

**4. Users open the link**

When a user opens the link, Gamezop looks for other users from your Property ID with the same `roomId` and matches them in a Battle.

***

## Optional roomDetails fields

Add these fields to `roomDetails` before you encode it, to customise the Battle.

### Identify your players

| Field | Description |
| - | - |
| `user` | An object with details of the user you are opening the game for. It contains: - `name`: the user's name - `puid`: your unique identifier for the user - `photo`: a URL of the user's profile photo Some games, such as Pool and Chess, show the name and photo in the game. If you don't pass `user`, the game uses generic names and photos. The [match outcome APIs](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/match-outcomes.md) and [client-side callbacks](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/client-side-callbacks.md) identify players by `user.puid`, so include `user` if you use them. Don't use personal information such as an email address or phone number as the `puid`; send a hashed identifier instead. |

### Configure matchmaking

| Field | Description |
| - | - |
| `minPlayers` | The minimum number of players needed to start a match. Defaults to 2. For example, in Ludo you can set it to 4 to only start matches with 4 players. Some games ignore this value. In Chess, for example, a match always has 2 players, even if you pass 4. |
| `maxPlayers` | The maximum number of players in a match. The maximum value is 5; if you pass a bigger number, 5 is used. If you don't pass a value, it is usually 2 or 5, depending on the game. Some games have a fixed limit. In Chess, for example, a match never has more than 2 players. In async games, up to 5 players can play in the same match and see one another's scores in real time. |
| `maxWait` | How long matchmaking runs, in seconds. If `minPlayers` aren't found within this time, the user sees a "No match found" screen and can try again. Defaults to 60. The minimum value is 5 and the maximum is 600. |

### Add bot opponents

| Field | Description |
| - | - |
| `allowBots` | Set to `true` to match users with bots pre-configured for your property when no opponent is found by the end of `maxWait`. Defaults to `false`. Contact your Gamezop Account Manager to configure these bots. Bots work in a [limited set of games](https://docs.google.com/spreadsheets/d/1LaDHx9_xBEJynyRNV3wKF67OYrWRK0-6Ua1_j4-gMEk). |
| `bots` | An array of your own bot profiles. Each profile can include `puid` (your identifier for the bot), `name`, and `photo` (a URL). If `bots` isn't empty, it is used instead of the pre-configured bots, whatever the value of `allowBots`. |

### Customise gameplay and the result screen

| Field | Description |
| - | - |
| `rounds` | The number of attempts each player gets in the match. The winner is decided on each player's best score across all their attempts. This depends on the game. Chess allows only 1 round per match, but in a single-player game you could pass 3 to let users play up to 3 times for a high score. Defaults to 1. The maximum value is 5. |
| `gameConfig` | A game-specific value that starts the game in a particular mode. For example, a Pool game may have 8 Ball and 9 Ball modes. See the [list of games that support this and their values](https://docs.google.com/spreadsheets/d/1LaDHx9_xBEJynyRNV3wKF67OYrWRK0-6Ua1_j4-gMEk/edit#gid=95886353). |
| `text` | The button shown at the bottom of the result and "No match found" screens. Defaults to `"go_home"`. Accepts: - `""`: no button is shown. Use the `match_result` or `match_not_found` [client-side callback](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/client-side-callbacks.md) to show your own UI on top of the screen. - `"go_home"`: shows a **Go Home** button. When the user taps it, you receive a `go_home` [client-side callback](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/client-side-callbacks.md). Use it to take the user back to your app or website. - `"play_again"`: shows a **Play Again** button. Tapping it starts matchmaking again with the same `roomDetails`. |

### Complete example

```json theme={null}
{
  "roomId": "ABC01",
  "user": {
    "name": "John Doe",
    "photo": "https://example.com/photos/user-1.jpg",
    "puid": "user-123"
  },
  "maxPlayers": 4,
  "minPlayers": 2,
  "maxWait": 60,
  "rounds": 1,
  "text": "go_home",
  "allowBots": true,
  "bots": [
    {
      "puid": "bot-123",
      "name": "Alex",
      "photo": "https://example.com/photos/bot-1.jpg"
    }
  ]
}
```

***

**Next steps**

> [card] [Track Battle match outcomes](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/match-outcomes.md)
>
> Receive each match's result on your server.

> [card] [Client-side callbacks](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/client-side-callbacks.md)
>
> Respond to Battle events in your app or website.

***


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