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

# Track Battle match outcomes

> Use the Create Match API and Receive Winners API together to track a Battle from matchmaking through its final result.

Licensed

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

To track Battle results on your server, you build one or both of these endpoints, and Gamezop's server calls them:

| Endpoint | When Gamezop calls it | Do you need it? |
| - | - | - |
| [Create Match API](#create-match-api) | When players are matched, or when no match is found | Optional. Build it if you want to set the `match_id` yourself, or refund entry fees when no match is found. If you don't, Gamezop generates the `match_id`. |
| [Receive Winners API](#receive-winners-api) | When a match ends | Build it to receive each match's final ranks and scores, along with its `match_id`. |

You can also call Gamezop's [Get Match Result API](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/get-match-result-api.md) at any time to fetch the result of a specific match.

## How Battle outcome tracking works

```mermaid theme={null}
flowchart TB
  subgraph matchCreation["1. Matchmaking and match creation"]
    direction LR
    launch["Your application<br/>Opens a Battle<br/>(roomId, puid)"] --> matching["Gamezop<br/>Matches players"] --> create["Gamezop calls<br/>Create Match API (optional)<br/>(room_id, status, puids)"]
    create -->|MATCH_FOUND| matchId["Your server<br/>Returns match_id"]
    create -->|NO_MATCH_FOUND| noMatch["Your server<br/>Refunds entry fees, if any"]
  end

  subgraph finalOutcome["2. Final outcome"]
    direction LR
    battle["Players<br/>Play the Battle"] --> winners["Gamezop sends<br/>Final results<br/>(match_id, puid,<br/>rank, score)"] --> outcome["Your server<br/>Saves the outcome"] --> reward["Reward winners<br/>or take your own action"]
  end

  matchCreation -->|After the match starts| finalOutcome

  classDef publisher fill:#eff6ff,stroke:#3b82f6,color:#1e3a8a,font-size:20px;
  classDef gamezop fill:#f5f3ff,stroke:#8b5cf6,color:#4c1d95,font-size:20px;
  classDef player fill:#fef3c7,stroke:#f59e0b,color:#78350f,font-size:20px;
  classDef outcome fill:#f0fdfa,stroke:#14b8a6,color:#134e4a,font-size:20px;
  classDef exception fill:#fff7ed,stroke:#f97316,color:#7c2d12,font-size:20px;

  class launch,matchId,outcome publisher;
  class matching,create,winners gamezop;
  class battle player;
  class reward outcome;
  class noMatch exception;
```

If you haven't built the Create Match API, Gamezop skips that call and generates the `match_id` itself.

### Secure your endpoints

Gamezop can send a bearer token with every call to your endpoints, so you can reject calls that don't come from Gamezop. If you want this, create a token and share it with your Gamezop Account Manager. Gamezop then includes it in each request:

```
Authorization: Bearer <your-token>
```

***

## Create Match API

An optional endpoint that Gamezop calls when players are matched, or when no match is found in time. If you return a `match_id`, Gamezop uses it for the rest of the match.

The `room_id` identifies the overall Battle room, while the `match_id` identifies one match played in that room. For example, Alice and Bob may play multiple matches in room `ABC01`. The `room_id` remains the same, but the winner can differ in each match. Winners are therefore associated with the `match_id`, not the `room_id`.

### Your API endpoint

For example: POST `https://api.publisher-xyz.com/games/create-match`

### Request body

| Name | Type | Description |
| - | - | - |
| `room_id` | String | This is the value that you pass as `roomId` in the encoded `roomDetails` object. You pass the `roomDetails` query parameter while [creating the Battle game link](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/overview.md#create-a-battle-game-link). |
| `status` | String | One of 2 options will be passed: `MATCH_FOUND` or `NO_MATCH_FOUND`. If you've charged an entry fee to your users, you can issue a refund in case no match is found. |
| `puids` | Array of strings | The `puid` values of the players matched together. You pass each player's `puid` within the `user` object in the encoded `roomDetails` object. |

Example request body:

```json theme={null}
{
  "room_id": "ABC01",
  "status": "MATCH_FOUND",
  "puids": ["user-123", "user-456"]
}
```

### HTTP response codes

Respond with a 200 when you return a `match_id`.

Expected response body:

```json theme={null}
{
  "success": true,
  "match_id": "XYZ_match_number_1"
}
```

When the status is `NO_MATCH_FOUND`, return `match_id` as an empty string.

> [!NOTE]
>
> **If you charge an entry fee**
>
> * **`MATCH_FOUND`:** before you return a `match_id`, check that every player in the request has paid. If any player hasn't, refund the others and respond with HTTP 200 and an empty `match_id`. The players then see the "No match found" screen.
> * **`NO_MATCH_FOUND`:** refund the entry fee for every player in the request.

***

## Receive Winners API

An endpoint that Gamezop calls when each match ends, with every player's final rank and score. Use it to save results or reward winners.

### Your API endpoint

For example: POST `https://api.publisher-xyz.com/games/receive-winners`

### Request body

| Name | Type | Description |
| :- | :- | :- |
| `match_id` | String | The match's identifier: the `match_id` your Create Match API returned, or the one Gamezop generated if you haven't built that API. |
| `scores` | Array of objects | One object per player, with the fields below. |
| `scores[].rank` | Number | The player's final rank. Players with the same score share a rank. |
| `scores[].puid` | String | The `user.puid` you passed in `roomDetails`. |
| `scores[].score` | Number | The player's final score in the match. |

Battles always use a game's single default mode, so scores here have no `leaderboardId`, unlike Individual Games scores.

Example request body:

```json theme={null}
{
  "match_id": "XYZ_match_number_1",
  "scores": [
    { "rank": 1, "puid": "user-123", "score": 100 },
    { "rank": 2, "puid": "user-456", "score": 80 }
  ]
}
```

### HTTP response codes

Respond with HTTP 200 and send back every player's `rank`, `puid` and `score`; all three fields are required. To show a prize on the result screen, add `prize` and `currency_icon` to any player. Both are optional.

Example response body:

```json theme={null}
{
  "success": true,
  "scores": [
    {
      "rank": 1,
      "puid": "user-123",
      "score": 100,
      "prize": 100,
      "currency_icon": "https://example.com/icon.png"
    },
    {
      "rank": 2,
      "puid": "user-456",
      "score": 80
    }
  ]
}
```

The result screen shows the final ranking, along with any prize you sent:

![Battle result screen showing the winner's prize next to their score](https://mintcdn.com/gamezop/41-X5ypvJ2MF-bmi/images/gamezop/battles/result-with-prize.png?fit=max\&auto=format\&n=41-X5ypvJ2MF-bmi\&q=85\&s=d3d4da61a024ae857be391a947b83431)

**Next steps**

> [card] [Get Match Result API](https://docs.platform.gamezop.com/publishers/gamezop/offerings/battles/integration/get-match-result-api.md)
>
> Fetch the result of a specific match at any time.

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