Affiliate Program Settings

9 vues Markdown

The two endpoints holding the commission rate, period, delay and payout floor.

Overview

The program settings decide how much commission is given, when and for how long. Two endpoints read and write one structure.

Three settings work together: the rate sets the size of the commission, the period says whether it comes once or on every renewal, and the delay says when the earnings count as payable.

The cookie duration answers a separate question: how many days after a click on the link a visitor can become a customer and still be credited to that partner.

Reference

Reading the Program Settings

get/api/v1/admin/affiliates/config
Affiliates/GetAffiliateConfig admin

Returns every setting of the affiliate program.

Response fields data — 11
enabledboolWhether the program is on. Service assignment is refused while it is off.
view_without_membershipboolWhether the program page opens to someone with no account.
show_commission_ratesboolWhether commission rates show on the product page.
commission_periodstringWhether commission comes once or on every renewal: onetime or lifetime.
commission_delayintThe days waited before commission counts as usable.
ratefloatThe default commission rate. A product can carry its own.
min_paymentobjectThe least that can be asked for in a payout.
amountfloatThe least amount.
currency_idintThe currency id of that amount.
cookie_durationintHow many days a referral is remembered.
redirectstringWhere a click on the link lands. The home page when empty.
payment_gatewaysobject[]The payout methods a partner can pick. Each element is an object holding a name per language.
contentobjectThe program page text per language.
Errors 1
insufficient_scope403The key lacks the required scope.
Request
curl 'https://panel.example.com/api/v1/admin/affiliates/config' \
  -H "Authorization: Bearer $API_KEY"
const res  = await fetch('https://panel.example.com/api/v1/admin/affiliates/config', {
  headers: { Authorization: `Bearer ${apiKey}` },
});
const { data } = await res.json();

const rate = data.rate;
const floor = data.min_payment.amount;
$ch = curl_init('https://panel.example.com/api/v1/admin/affiliates/config');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => ['Authorization: Bearer ' . $apiKey],
]);

$body = json_decode(curl_exec($ch), true);
curl_close($ch);
// Read here BEFORE saving: the save writes a default over any field you leave out.
$cfg = Api::Affiliates()->GetAffiliateConfig()['data'];
$cfg['rate'] = 15;

Saving the Program Settings

put/api/v1/admin/affiliates/config
Affiliates/SaveAffiliateConfig admin a full write

Writes the whole set of settings and returns where they now stand.

Body 11
enabledboolWhether the program is on. Service assignment is refused while it is off.
view_without_membershipboolWhether the program page opens to someone with no account.
show_commission_ratesboolWhether commission rates show on the product page.
commission_periodstringWhether commission comes once or on every renewal: onetime or lifetime.
commission_delayintThe days waited before commission counts as usable.
ratefloatThe default commission rate. A product can carry its own.
min_paymentobjectThe least that can be asked for in a payout.
amountfloatThe least amount.
currency_idintThe currency id of that amount.
cookie_durationintHow many days a referral is remembered.
redirectstringWhere a click on the link lands. The home page when empty.
payment_gatewaysobject[]The payout methods a partner can pick. Each element is an object holding a name per language.
contentobjectThe program page text per language.
Response fields data — 11
dataobjectThe settings as they now stand. Same shape as the read endpoint.
Errors 1
insufficient_scope403The key lacks the required scope.
Request
curl -X PUT 'https://panel.example.com/api/v1/admin/affiliates/config' \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"enabled":true,"commission_period":"lifetime","commission_delay":30,"rate":10,"cookie_duration":30,"min_payment":{"amount":50,"currency_id":840}}'
const read = await fetch('https://panel.example.com/api/v1/admin/affiliates/config', {
  headers: { Authorization: `Bearer ${apiKey}` },
});
const { data: cfg } = await read.json();

const res = await fetch('https://panel.example.com/api/v1/admin/affiliates/config', {
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ ...cfg, rate: 15 }),
});
$cfg = $current;                 // GET /affiliates/config yaniti
$cfg['rate'] = 15;

$ch = curl_init('https://panel.example.com/api/v1/admin/affiliates/config');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'PUT',
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode($cfg),
]);

$body = json_decode(curl_exec($ch), true);
curl_close($ch);
// A FULL WRITE: every field you leave out returns to its default (texts and payout methods GO EMPTY).
$cfg = Api::Affiliates()->GetAffiliateConfig()['data'];
$cfg['rate'] = 15;

Api::Affiliates()->SaveAffiliateConfig($cfg);

Pitfalls

The save is a full write and not a patch

The save endpoint writes every field in the body. A field you leave out is not kept and returns to its default: numbers to zero, texts to empty, the payout methods and program texts to an empty list. To change the rate alone, read first and write over the object that comes back.

The payout methods are a list and not a language map

The program text is an object with a key per language. The payout methods are a list whose every element holds a name per language of its own. Writing them the same way empties the method list, and partners see no option when asking for a payout.

The commission period is not checked

The period field is cleaned up alone and not checked against the values that are known. A misspelled value saves without a word, no error comes back, and the period does not behave as you expect. Read the value back after saving.

Turning the program off does not wipe existing earnings

While the program is off a new service assignment is refused, and existing balances and waiting payout requests stay where they are. Turning it off stops new commission from being made rather than freezing what exists.

Cet article vous a-t-il été utile ?

Merci pour votre retour !

Besoin d'aide supplémentaire ?

Notre équipe d'assistance est disponible 24h/24 pour tout ce que vous ne trouvez pas ci-dessus.