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

# Postback instruction for PHP

> There's a guide for clients who need to implement the Postback integration on PHP.

November 9, 2026

Each request has to have a header with the user's authentication key.

X-Api-Key: #Your key#

You can find and manage the X-Api-Key in [your account settings](https://support.tapfiliate.com/getting-started/essential-account-settings/how-to-find-account-id-and-api-key.md#h_ce8e59730e).\

Your X-Api-Key - has to be saved in secure storage (e.g. database, environment variables).

**Basic concepts**

Defining constants for further usability.

```
define('TAP_COOKIE_DAYS', 90); // Number of days cookies are stored for
define('TAP_COOKIE_NAME', 'tap_data'); // Cookie name
define('TAP_CONVERSION_POSTBACK_URL', 'https://api.tapfiliate.com/1.7/pb/con/c/'); // Link to the endpoint for working with conversions
define('TAP_CUSTOMER_POSTBACK_URL', 'https://api.tapfiliate.com/1.7/pb/cus/c/'); // Link to the endpoint for working with customers
```

For parsing data from global arrays when going to the site, the desired transition parameters need to be stored in the user's cookies.

```php theme={null}
function parseAndSaveDataOnClick()
{
    $resultArray = [];

    if ($assetData = $_GET['aid'] ?? $_GET['asset_id'] ?? $_GET['a'] ?? $_POST['aid'] ?? $_POST['asset_id'] ?? $_POST['a'] ?? null) {
        $resultArray['asset_id'] = $assetData;
    }

    if ($sourceData = $_GET['sid'] ?? $_GET['source_id'] ?? $_GET['s'] ?? $_POST['sid'] ?? $_POST['source_id'] ?? $_POST['s'] ?? null) {
        $resultArray['source_id'] = $sourceData;
    }

    if ($refData = $_GET['refc'] ?? $_GET['referral_code'] ?? $_GET['ref'] ?? $_POST['refc'] ?? $_POST['referral_code'] ?? $_POST['ref'] ?? null) {
        $resultArray['referral_code'] = $refData;
    }

    if (empty($resultArray)) {
        return; // No affiliate data in this request: keep the cookie saved earlier
    }

    setcookie(TAP_COOKIE_NAME, json_encode($resultArray), time() + 60 * 60 * 24 * TAP_COOKIE_DAYS, '/');
}
```

When a target action happens a customer needs to be created and a conversion tracked.

**Create a customer**\

To create a customer, an array with data in it needs to be passed.

Required parameters:\

• `customer id` The unique identifier of the customer in your system.

You have to also send one of the parameters:\

• `referral code` An affiliate’s referral code.\

• `coupon` An affiliate’s coupon code.\

• `asset id` and `source id` A source id or an asset id.

Those parameters that come in the link will be taken from it and saved in cookies, the rest must be entered manually.

```php theme={null}
function createCustomer($customerData)
{
    $requestData = array_merge(
        json_decode($_COOKIE[TAP_COOKIE_NAME] ?? '', true) ?: [],
        $customerData
    );

    return sendRequestToApi(TAP_CUSTOMER_POSTBACK_URL, $requestData);
}
```

**Сreate a conversion**\

To create a conversion an array with data in it needs to be passed.

Required parameters:\

• `external id` A unique id for this conversion.

You have to also send one of the parameters:\

• `referral code` An affiliate’s referral code.\

• `coupon` An affiliate’s coupon code.\

• `asset id` and `source id` A source id or an asset id.

Those parameters that are included in the link will be taken from it and saved in cookies, the rest must be entered manually.

```php theme={null}
function createConversion($conversionData)
{
    $requestData = array_merge(
        json_decode($_COOKIE[TAP_COOKIE_NAME] ?? '', true) ?: [],
        $conversionData
    );

    return sendRequestToApi(TAP_CONVERSION_POSTBACK_URL, $requestData);
}
```

After that, a customer with a conversion attached to it should appear in your Tapfiliate interface.

Example function for sending POSTBACK.\

To create customers/conversions, an array with data in it needs to be passed.

```php theme={null}
function sendRequestToApi($url = '', $data = [])
{
    $defaultHeaders = [
        'X-Api-Key: ' . getenv('TAPFILIATE_API_KEY'), // API key (taken from environment variables in this case)
        'Content-type: application/json',
        'Accept: application/json',
    ];
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $defaultHeaders);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);

    if (curl_errno($ch)) {
        throw new Exception(curl_error($ch));
    }

    return $response;
}
```

**Note:** S2S/Postback tracking is an advanced feature. As such, set up of this feature falls outside the scope of our support. You may [need a developer](https://support.tapfiliate.com/advanced-configurations-automation/api-webhooks-automations/need-a-tech-expert-how-to-find-the-right-developer-for-your-program.md) to assist in setting this up.


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