# Webhooks: automatic alerts

> Get alerts for low balance, GB exhausted, paid top-ups and new customers, with HMAC-SHA256 signatures and verification examples.
> Page: https://rh7proxys.com/en/docs/revenda-webhooks · Index: https://rh7proxys.com/llms.txt

A webhook is an alert that RH7 sends to your system when something happens: low balance, a customer out of GB, a paid top-up. This way your system reacts right away, without polling the API.

You can also set it up in the panel, in the reseller **Alerts** tab.

## Events

| Event | When it fires | Data (`data`) |
|---|---|---|
| `pool.recharge.confirmed` | The GB purchase for your balance was paid | `recharge_id`, `gb_added`, `amount_brl` |
| `pool.balance.low` | Your balance dropped below the threshold (default 10 GB) | `gb_available`, `threshold_gb` |
| `client.created` | A customer was created | `client_id`, `name`, `proxy_username` |
| `client.suspended` | A customer was suspended | `client_id` |
| `client.gb.low` | A customer's proxy dropped below the threshold (default 1 GB) | `client_id`, `name`, `proxy_username`, `gb_allocated`, `gb_used`, `gb_remaining`, `threshold_gb` |
| `client.gb.exhausted` | A customer's proxy ran out of GB | `client_id`, `name`, `gb_allocated`, `gb_used` |
| `subuser.created` | A customer was created through the API | `subuser_id`, `name`, `email`, `proxy_username` |
| `subuser.allocated` | GB was moved to a customer | `subuser_id`, `gb_allocated` |
| `subuser.deleted` | A customer was deleted | `subuser_id` |
| `webhook.test` | You requested a test | `message` |

Balance alerts are checked every 10 minutes and sent once per drop: they only fire again after the balance goes back up.

## Register

```bash
curl -X POST https://api.rh7proxys.com/webhooks \
  -H "x-api-key: rh7_your_key" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://yoursite.com/rh7/avisos", "events": ["client.gb.low", "pool.balance.low", "pool.recharge.confirmed"]}'
```

- The `url` must be `https://` and public.
- `events` accepts the list of events or `["*"]` for all of them (default).
- The response includes the `secret` only once. Save it: it verifies the signature.

Other routes: `GET /webhooks` (list), `PATCH /webhooks/{id}` (change `url`, `events` or `active`), `DELETE /webhooks/{id}` (delete).

## Change the thresholds

```bash
curl -X PATCH https://api.rh7proxys.com/webhooks/settings \
  -H "x-api-key: rh7_your_key" \
  -H "Content-Type: application/json" \
  -d '{"client_low_gb": 2, "pool_low_gb": 50}'
```

Both range from 0.1 to 1000 GB.

## What reaches your system

A `POST` with JSON:

```http
POST /rh7/avisos HTTP/1.1
Content-Type: application/json
X-RH7-Event: client.gb.low
X-RH7-Signature: 5d41402abc4b2a76b9719d911017c592...
```

```json
{
  "event": "client.gb.low",
  "reseller_id": "uuid",
  "occurred_at": "2026-11-26T18:20:00Z",
  "data": { "client_id": "uuid", "name": "Cliente Loja 1", "proxy_username": "cliente_ab12", "gb_allocated": 10, "gb_used": 9.2, "gb_remaining": 0.8, "threshold_gb": 1 }
}
```

Respond with any 2xx code within 8 seconds. Do the heavy work after you respond.

## Verify the signature

`X-RH7-Signature` is the HMAC-SHA256 of the exact body received, using your `secret`, in lowercase hexadecimal. Compute it over the raw text, before parsing it into an object.

### Node.js (Express)

```js
import crypto from "node:crypto";
import express from "express";

const app = express();
app.post("/rh7/avisos", express.raw({ type: "application/json" }), (req, res) => {
  const esperado = crypto.createHmac("sha256", process.env.RH7_WEBHOOK_SECRET).update(req.body).digest("hex");
  const recebido = req.get("X-RH7-Signature") || "";
  const ok = recebido.length === esperado.length &&
    crypto.timingSafeEqual(Buffer.from(recebido), Buffer.from(esperado));
  if (!ok) return res.status(401).end();

  const aviso = JSON.parse(req.body.toString("utf8"));
  res.status(200).end();
  // handle aviso.event and aviso.data here
});
```

### Python (Flask)

```python
import hmac, hashlib, os
from flask import Flask, request, abort

app = Flask(__name__)

@app.post("/rh7/avisos")
def avisos():
    esperado = hmac.new(os.environ["RH7_WEBHOOK_SECRET"].encode(), request.get_data(), hashlib.sha256).hexdigest()
    if not hmac.compare_digest(esperado, request.headers.get("X-RH7-Signature", "")):
        abort(401)
    aviso = request.get_json()
    return "", 200
```

### PHP

```php
$corpo = file_get_contents("php://input");
$esperado = hash_hmac("sha256", $corpo, getenv("RH7_WEBHOOK_SECRET"));
if (!hash_equals($esperado, $_SERVER["HTTP_X_RH7_SIGNATURE"] ?? "")) {
    http_response_code(401);
    exit;
}
$aviso = json_decode($corpo, true);
http_response_code(200);
```

## Retries

If your system does not respond with 2xx, RH7 tries again: 5 minutes later, then with the wait doubling each time, up to 6 hours between attempts. There are up to 8 attempts in total. Retries include the `X-RH7-Retry` header with the attempt number.

The same alert can arrive more than once. Use `event` + `occurred_at` + the id in `data` so you do not process it twice.

## Test

```bash
curl -X POST https://api.rh7proxys.com/webhooks/WEBHOOK_ID/test \
  -H "x-api-key: rh7_your_key"
```

Sends a `webhook.test` to that address only. The response tells you whether it answered with 2xx (`ok: true`).

## View deliveries

`GET /webhooks/deliveries?webhook_id=...&limit=50` lists each attempt, with the code your system responded with. `GET /webhooks/deliveries/{id}` shows the body sent and the response.
