# Webhooks

You will receive a webhook notification when the customer has created their webstore and their game server is ready to have the Tebex plugin automatically installed. Upon receipt of the webhook you should do the following:

1. Download the Tebex plugin and install it onto the game server using the provided url.
2. Download the premade config file and install it onto the game server (or manually create the config file depending on the game type, using the secret parameter in the webhook).
3. Restart the game server to allow the Tebex Plugin to notify us that the plugin has been installed and authenticated against the webstore.

### Setup Your Webhook URL

You can specify the url of your webhook handler (such as serverhost.com/tebex.php) within the settings section of your affiliate control panel.

### Authentication

To verify that the webhook has been sent from Tebex, we send a X-Tebex-Signature header that contains a HMAC using SHA256 created by the POST body (JSON) using your Webhook Signature Secret as the key.

You can find your Webhook Signature Secret within the setting section of your affiliate panel and example of calculating the signature in PHP is below:

```php
$body = file_get_contents("php://stdin");
$secret = "myagreedsecret";
$signature = hash_hmac("sha256", $body, $secret);

if ($signature != $_SERVER['HTTP_X_TEBEX_SIGNATURE']) {
    return "Invalid signature";
}
```

### Example Webhook Notification

```javascript
{
    "reference": "123456",
    "secret": "9a6747fc6259aa374ab4e1bb03074b6ec672cf99",
    "game_type": {
        "id": 1,
        "plugins": {
            "bukkit": {
                "platform": "bukkit",
                "version": "10.2",
                "url": "https://d2vpaemuugs53a.cloudfront.net/latest/10.2/bukkit/BuycraftX.jar",
                "config": "http://affiliate.tebex.io/api/referrals/123456/config/bukkit"
            },
            "sponge": {
                "platform": "sponge",
                "version": "10.2",
                "url": "https://d2vpaemuugs53a.cloudfront.net/latest/10.2/sponge/BuycraftX.jar",
                "config": "http://affiliate.tebex.io/api/referrals/123456/config/sponge"
            },
            "bungeecord": {
                "platform": "bungeecord",
                "version": "10.2",
                "url": "https://d2vpaemuugs53a.cloudfront.net/latest/10.2/bungeecord/BuycraftX.jar",
                "config": "http://affiliate.tebex.io/api/referrals/123456/config/bungeecord"
            },
            "forge": {
                "platform": "forge",
                "version": "12.0.1",
                "url": "https://d2vpaemuugs53a.cloudfront.net/latest/minecraft-java/12.0.1/forge/BuycraftX.jar",
                "config": "http://affiliate.tebex.io/api/referrals/123456/config/forge"
            }
        }
    },
    "setup_at": "2020-11-17T09:41:57+00:00"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tebex.io/developers/affiliate-api/webhooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
