Track Affiliate Earnings

Track and manage your affiliate earnings via the API.

The Commissions endpoint lets you track your affiliate earnings programmatically.

Listing Commissions

const response = await fetch(`${BASE_URL}/commissions`, { headers });
const { data: commissions } = await response.json();

commissions.forEach(c => {
  console.log(`${c.id}: $${c.amount_usd} from ${c.order.product.name}`);
});

Commission Object

FieldDescription
idUnique commission transaction identifier
amount_satoshiCommission amount in satoshis
amount_eurCommission amount in EUR
amount_usdCommission amount in USD
currencyCurrency code (typically XBT for Bitcoin)
balanceYour account balance after this commission
orderNested object containing order details
dateWhen the commission was earned (ISO 8601)

Pagination

The commissions endpoint supports pagination:

// Get all commissions with pagination
async function getAllCommissions() {
  const commissions = [];
  let start = 0;
  const limit = 50;
  
  while (true) {
    const response = await fetch(
      `${BASE_URL}/commissions?start=${start}&limit=${limit}`,
      { headers }
    );
    const data = await response.json();
    commissions.push(...data.data);
    
    if (data.data.length < limit) break;
    start += limit;
  }
  
  return commissions;
}

Calculating Earnings

Total Earnings

async function getTotalEarnings() {
  const response = await fetch(`${BASE_URL}/commissions`, { headers });
  const { data: commissions } = await response.json();
  
  const totalUSD = commissions.reduce((sum, c) => sum + c.amount_usd, 0);
  const totalEUR = commissions.reduce((sum, c) => sum + c.amount_eur, 0);
  
  console.log(`Total: $${totalUSD.toFixed(2)} USD / €${totalEUR.toFixed(2)} EUR`);
  return { usd: totalUSD, eur: totalEUR };
}

Monthly Earnings Report

async function getMonthlyEarnings(year, month) {
  const response = await fetch(`${BASE_URL}/commissions`, { headers });
  const { data: commissions } = await response.json();
  
  const targetMonth = `${year}-${month.toString().padStart(2, '0')}`;
  const monthly = commissions.filter(c => c.date.startsWith(targetMonth));
  
  return {
    period: targetMonth,
    count: monthly.length,
    total_usd: monthly.reduce((sum, c) => sum + c.amount_usd, 0),
    total_eur: monthly.reduce((sum, c) => sum + c.amount_eur, 0)
  };
}

Building a Commission Dashboard

const API_ID = process.env.BITREFILL_API_ID;
const API_SECRET = process.env.BITREFILL_API_SECRET;
const BASE_URL = 'https://api.bitrefill.com/v2';

const token = Buffer.from(`${API_ID}:${API_SECRET}`).toString('base64');
const headers = { 'Authorization': `Basic ${token}` };

async function getDashboardData() {
  const response = await fetch(`${BASE_URL}/commissions`, { headers });
  const { data: commissions } = await response.json();
  
  const now = new Date();
  const thisMonth = now.toISOString().slice(0, 7);
  const thisMonthCommissions = commissions.filter(c => c.date.startsWith(thisMonth));
  
  return {
    overview: {
      totalCommissions: commissions.length,
      totalEarningsUSD: commissions.reduce((sum, c) => sum + c.amount_usd, 0),
      thisMonthEarningsUSD: thisMonthCommissions.reduce((sum, c) => sum + c.amount_usd, 0),
      thisMonthCount: thisMonthCommissions.length
    },
    recentCommissions: commissions.slice(0, 10)
  };
}

Payout Information

Commissions are paid out according to your affiliate agreement. The API provides:

  • When commissions are earned (date)
  • Commission amounts in multiple currencies (amount_usd, amount_eur, amount_satoshi)
  • Your account balance after each commission (balance)
  • Full order details for each commission (order)

For payout schedules and thresholds, contact your affiliate manager.