Every reply your platform sends to a getbalance or balance_adj request must carry a hash field. With it we know that the reply came from your platform and that it was not changed on the way. The check is enabled by default for every operator account, in the trial environment too.
This is the second use of your API Encryption Key. Its first use goes the other way: you verify the hashed_result of every request we send to your endpoints (see Security - Trusting our data). The key itself is never sent in a request or a reply.
The rule
Build the string
status|balance|uniqid: three values, joined by the|character.status: the status value you return, as the exact string you send (for example1).balance: the balance you return, as the exact string you send (for example1250.50). When the reply has nobalancefield, use the string of itscreditfield. When the reply has neither, as in a refusal, leave this part empty.uniqid: theuniqidvalue from our request, unchanged.
Compute the HMAC-SHA256 of that string with your API Encryption Key. Use the key exactly as issued, as a text string.
Send the result as a lowercase hexadecimal string (64 characters) in the
hashfield of the reply.
Send status and balance as JSON strings, so the bytes you sign are the bytes we read. A JSON number can lose its last zero on the way (1250.50 is read as 1250.5), and then the hash does not match.
Worked example
Test your code against this example before the first real request. The key used in it is your-secret-key.
The request we send
{
"command":"getbalance",
"userid":"224",
"login":"u241_8841",
"timestamp":"2026-07-02 14:10:00",
"currency":"USD",
"internal_session_id":"abc123",
"uniqid":"a1b2c3d4e5f6",
"type":"getbalance",
"custom_data":"",
"hashed_result":"05ea6df60e2ba0a14facb2128e083f4cf288493b7cbc5f614b8348aae638172d"
}The hashed_result shown is the value you compute when you verify this request with the key your-secret-key.
The reply you return
{"status":"1","balance":"1250.50","hash":"6bcbaa67aef69e9cb5d9d477222b3f4ecd7322f252bf1eda4007e19315c6bfa8"}The hash of that reply
string to sign : 1|1250.50|a1b2c3d4e5f6
hash : HMAC-SHA256("your-secret-key", "1|1250.50|a1b2c3d4e5f6") as hex
= 6bcbaa67aef69e9cb5d9d477222b3f4ecd7322f252bf1eda4007e19315c6bfa8A refusal is signed in the same way. For the reply {"status":"-1","errormsg":"Invalid user","hash":"..."} to the same request, the string to sign is -1||a1b2c3d4e5f6 (the balance part is empty) and the hash is 389ada0afd9ae2f0e17d7917ec04be15f00a6524908ce962f5e2664fe25e7944.
Sample code
// $data = the request we sent, decoded from JSON, after you verified its hashed_result
$status = '1'; // the exact string you return
$balance = '1250.50'; // the exact string you return
$reply = array(
'status' => $status,
'balance' => $balance,
'hash' => hash_hmac('sha256', $status . '|' . $balance . '|' . $data['uniqid'], $api_encryption_key),
);
header('Content-Type: application/json');
echo json_encode($reply);What happens when the hash is missing or wrong
A reply with a missing or wrong hash is treated as no reply, whatever its status says:
Balance request (
getbalance): the balance is not read and the player cannot play. A balance request is not sent again.Bet: the bet is not taken. It is handled as a bet that received no reply (see Handling Timeouts).
Win: the win is held and sent again with the same
uniqiduntil a correctly signed reply arrives.
This applies to a refusal too: a reply with the status 0 or -1 and no valid hash is not read as a refusal. Sign every reply, the refusals included.
For this check only the JSON body is read: a reply with a missing or wrong hash is treated as no reply whatever its HTTP status code. A correctly signed refusal (status 0 or -1) to a win, a jackpot, a cancel or a bet that is sent with an HTTP 5xx status code is also treated as no reply: a win, a jackpot or a cancel stays pending and is resent with the same uniqid; a bet is handled as a timed-out bet (see Handling Timeouts). See the win_rejected article.
Check your implementation
The automated test tool checks the reply signature of your endpoint (test 15). See Testing/Finalizing your Integration.
Send the hash field on every reply from your first integration test. Ask us only if you need the check switched off during a migration.
The reply formats of both endpoints are described in Receive Data from RGS-CWS API - Seamless Wallet.