AffiliatePipe

Partner API / A weekly email report

A weekly email report

A Monday email comparing this week with last, from a PHP script and cron.

<?php
$get = function (string $period) {
    $ch = curl_init('https://api.affiliatepipe.com/v1/stats?period=' . $period);
    curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('AP_KEY')]]);
    return json_decode(curl_exec($ch), true);
};
$week = $get('7d');
$month = $get('30d');
$avg = round($month['clicks'] / 30 * 7);
$body = "Clicks this week: {$week['clicks']} (30 day average {$avg} a week)\n"
      . "Sales: {$week['conversions']}\n"
      . 'Pending: $' . number_format($week['pending']['amount'] / 100, 2) . "\n";
mail('[email protected]', 'Your AffiliatePipe week', $body);
0 7 * * 1 AP_KEY=ap_live_... php /home/you/ap_weekly.php