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

# Server-side webhooks

> Receive Individual Games score updates through a server-to-server webhook.

Licensed

Gamezop can send score updates from Individual Games to your backend. Use this data to build leaderboards, save score data, or reward users.

A **gameplay** is a single run of a game, from the moment the player starts playing until the game ends. If the player plays again, a new gameplay starts. All the gameplays from when the game loads until the game page is refreshed or reloaded make up one session.

## How server-side webhooks work

```mermaid theme={null}
flowchart LR
  setup["Your server<br/>Provides a webhook URL"] --> launch["Your application<br/>Opens the game with a puid"]
  launch --> game["Game ends<br/>(over state is triggered)"]
  game --> gamezop["Gamezop's server<br/>Sends the score update<br/>(puid, gameCode,<br/>state: over, score: 20)"]
  gamezop --> webhook["Your server"]
  webhook --> save["Save score data"]
  webhook --> leaderboard["Update a leaderboard"]
  webhook --> reward["Reward the player"]

  classDef setup fill:#eff6ff,stroke:#3b82f6,color:#1e3a8a,font-size:22px;
  classDef game fill:#fef3c7,stroke:#f59e0b,color:#78350f,font-size:22px;
  classDef delivery fill:#f5f3ff,stroke:#8b5cf6,color:#4c1d95,font-size:22px;
  classDef action fill:#f0fdfa,stroke:#14b8a6,color:#134e4a,font-size:22px;

  class setup,launch setup;
  class game game;
  class gamezop,webhook delivery;
  class save,leaderboard,reward action;
```

***

## Configure the webhook

To receive user scores, provide a POST API or webhook URL. Gamezop sends score updates to this endpoint.

In order for this to work, you must also append a `puid` query parameter to the game `url` received in the All Games API.

For example: [https://3025.play.gamezop.com/g/NyM\_JGWcx?puid=user-123](https://3025.play.gamezop.com/g/NyM_JGWcx?puid=user-123)

The value of this `puid` param must be a unique user identifier for the user playing the game.  Max supported length of this value is **100 characters**. Scores are always scoped to a game and user identifier.

### Your webhook endpoint

POST `https://api.publisher-xyz.com/games/score`

Gamezop posts user scores to your webhook.

### Headers

| Name | Type | Description |
| - | - | - |
| Authorization: Bearer | String | We can add in a bearer token in the authorization headers if you require us to. |

Upon receiving scores from us, you must respond with an HTTP 200 Status Code

In the body of the webhook, Gamezop will send a JSON object when your users' scores update. The data body will contain the following fields:

| Key | Description |
| - | - |
| `gameCode` | Unique code assigned to each game. This is the `code` value received in the [All Games API](https://docs.platform.gamezop.com/publishers/gamezop/guides/all-games-api.md). |
| `sessionId` | Unique session identifier generated by Gamezop. It remains the same throughout a session. A session ends when the game page is refreshed or reloaded. |
| `gamePlayId` | Unique gameplay identifier generated by Gamezop. It remains the same throughout a gameplay. A session can contain multiple gameplays: each time the user loses and plays again, a new gameplay starts. |
| `timestamp` | Unix timestamp. Denotes the exact time at which this score was made by the user. |
| `score` | Score made by the user. |
| `leaderboardId` | The leaderboard within the game against which the score was recorded. (A Leaderboard is the category a score belongs to, such as a game mode. It is not a ranked list of scores.) |
| `puid` | User identifier passed by you as `puid` parameter in the game URL. |
| `country` | The ISO 3166-2 country code for the country from which the user is playing the game. |
| `duration` | Total time spent in the gameplay up until the point of the webhook call (captured in milliseconds). When a new gameplay starts, this is reset to 0. |
| `state` | Denotes the state of game at the time the `score` was made. It can be one of the following values: 1. **loaded**: `score` is always 0 with this state. It just means that the game finished loading. 2. **start**: This is fired at the start of every new gameplay. `score` and `duration` are 0 in this state update. 3. **playing**: This state means that the game is being played by the user. As the user's score keeps changing, we keep sending them to your API 4. **over**: The `score` received with this state value denotes the user's score when the game got over. Within the same session, a user can play again several times. This means that there may be several `over` states within the same session. 5. **levelup**: In case of level-based games, this state denotes the completion of a level. |

For client-side game events, see [Individual Games client-side callbacks](https://docs.platform.gamezop.com/publishers/gamezop/offerings/individual-games/client-side-callbacks.md).

***


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