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

# User Balance

> This API is used to get the player's wallet balance.

```http theme={null}
  POST  /user/balance
```

## Headers

<ParamField header="x-api-key" type="string" required>
  A unique identifier associated with operator calling API.
</ParamField>

<ParamField header="x-signature" type="string" required>
  A SHA256 HMAC signature generated using the request body and timestamp.
  Format: HMAC\_SHA256(JSON.stringify(data) + '|' + timestamp), signed using the
  provided secret key.
</ParamField>

<ParamField header="x-timestamp" type="string" required>
  An Unix timestamp (milliseconds) when the request was sent. Ensure the same
  value is used in signature generation.
</ParamField>

<ParamField header="content-type" type="string" required>
  Must be set to `application/json`
</ParamField>

## Request Body

<ParamField body="sessionId" type="string" required>
  A unique identifier for the session you want to retrieve the balance for.
</ParamField>

<ParamField body="playerId" type="string" required>
  A unique identifier of the player placing the bet.
</ParamField>

<ParamField body="gameId" type="string" required>
  Unique identifier for the game.
</ParamField>

## Response

<ResponseField name="status" type="string" required>
  Code indicates status of the request weather it is succeed or failed. We have listed error codes <a href="/introduction#error-codes">here</a>
</ResponseField>

<ResponseField name="sessionId" type="string" required> The unique identifier for the session. </ResponseField>

<ResponseField name="balance" type="number" required>
  The current balance of the player.

  <Note>
    To maintain precision and avoid floating-point errors, the balance field is processed as an integer value by multiplying the actual amount by `100000`.

    For example, a balance of `12.34567` will be represented as `1234567` in the API.
  </Note>
</ResponseField>

<RequestExample>
  ```bash Shell theme={null}
  curl --request POST \
    --url 'https://partner-platform-url/user/balance' \
    --header 'content-type: application/json' \
    --header 'x-api-key: <x-api-key>' \
    --header 'x-signature: <x-signature>' \
    --header 'x-timestamp: <x-timestamp>' \
    --data '{
      "sessionId": "f1dfc865-584c-4cba-a175-06172b2a41141731504451691",
      "playerId": "18865671",
      "gameId": "G1720761376617"
  }'
  ```

  ```javascript NodeJS theme={null}
  const axios = require('axios');

  const url = 'https://partner-platform-url/user/balance';
  const headers = {
      'content-type': 'application/json',
      'x-api-key': '<x-api-key>',
      'x-signature': '<x-signature>',
      'x-timestamp': '<x-timestamp>'
  };
  const data = {
      sessionId: "f1dfc865-584c-4cba-a175-06172b2a41141731504451691",
      playerId: "18865671",
      gameId: "G1720761376617"
  };

  axios.post(url, data, { headers })
      .then(response => {
          console.log(response.data);
      })
      .catch(error => {
          console.error(error);
      });
  ```

  ```python Python theme={null}
  import requests

  url = "https://partner-platform-url/user/balance"
  headers = {
      "content-type": "application/json",
      "x-api-key": "<x-api-key>",
      "x-signature": "<x-signature>",
      "x-timestamp": "<x-timestamp>"
  }
  data = {
      "sessionId": "f1dfc865-584c-4cba-a175-06172b2a41141731504451691",
      "playerId": "18865671",
      "gameId": "G1720761376617"
  }

  response = requests.post(url, headers=headers, json=data)
  print(response.json())
  ```

  ```php PHP theme={null}
  <?php
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://partner-platform-url/user/balance",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
      "content-type: application/json",
      "x-api-key: <x-api-key>",
      "x-signature: <x-signature>",
      "x-timestamp: <x-timestamp>"
    ],
    CURLOPT_POSTFIELDS => json_encode([
      "sessionId" => "f1dfc865-584c-4cba-a175-06172b2a41141731504451691",
      "playerId" => "18865671",
      "gameId" => "G1720761376617"
    ]),
  ]);

  $response = curl_exec($curl);
  curl_close($curl);

  echo $response;
  ?>
  ```
</RequestExample>

<ResponseExample>
  ```json SUCCESS theme={null}
  {
    "status": "RS_OK",
    "sessionId": "f1dfc865-584c-4cba-a175-06172b2a41141731504451691",
    "balance": 50000000
  }
  ```

  ```json FAILURE theme={null}
  {
    "status": "RS_ERROR",
    "message": "Oops! Something went wrong. Please refresh the page or try again in a moment"
  }
  ```
</ResponseExample>
