MMashDiv

API and data model

Every affiliate endpoint with its permission, the six database tables and what is unique about each, the hourly evaluation job, and the settings keys the engine reads.

6 min readUpdated 20 October 2026api, endpoints, tables, cron, settings, applications, referral code

Every route in this addon lives under /api/affiliate or /api/admin/affiliate. Nothing is served from /api/mlm — that path exists in the licensing route map but has no handlers behind it.

Member endpoints

Five of these answer without a session: the statistics, the landing page, the rates, the member's own standing (which tells a visitor which switches are set) and the Referral Program. All five read the session when there is one, because what they send depends on who is asking. The rest need a session, and all of them scope their data to the calling user — there is no way for a member to read somebody else's downline or rewards.

GET/api/affiliate/stats
Public programme statistics — affiliate count, total paid out, average monthly earnings, success rate. With Show Commissions off, the two money figures are zero for a viewer who is not an affiliate
GET/api/affiliate/landing
Everything the public landing page renders: stats, active conditions, top five earners and recent reward activity. With Show Commissions off, a viewer who is not an affiliate gets no conditions, leaderboard or reward activity and zero payout figures
GET/api/affiliate/condition
Active Affiliate Program conditions, filtered to the addons this install actually has enabled. An empty list when Show Commissions is off and the viewer is not an affiliate
GET/api/affiliate/application
The caller's standing: signedIn, applicationRequired, status NONE|PENDING|APPROVED|REJECTED, approved, code, message, reviewNote, appliedAt, reviewedAt, showCommissions and referralProgram. Answers a signed-out visitor with the switches
POST/api/affiliate/application
Applies to the Affiliate Program. Optional message up to 1000 characters. Refused with a 400 when applications are not required and with a 409 when the caller is already approved or already waiting. A rejected applicant is re-opened as waiting, keeping the original application date
GET/api/affiliate/referral-program
The Referral Program: enabled, its active one-time conditions with the referrer's and the friend's reward, and the viewer's standing
PUT/api/affiliate/code
Chooses the caller's personal referral code (3 to 32 characters, any case, stored in capitals). Approved affiliates only: 403 otherwise; 400 for a code that is empty, malformed or reserved; 409 when taken
DELETE/api/affiliate/code
Removes the caller's personal code and frees it. 404 when they have none. The standing itself stays
GET/api/affiliate/code/availability
Is this code free? Answers 200 with available and, when not, a reason of EMPTY, FORMAT, RESERVED or TAKEN. A code the caller already holds reads as available. Advisory: saving is what claims it
GET/api/affiliate/
The signed-in member's dashboard — referral counts, earnings and growth against the previous period. Accepts period=1m|3m|6m|1y
GET/api/affiliate/network
The member's network tree, rendered according to the configured structure, plus their upline and lifetime rewards
GET/api/affiliate/referral
Paginated list of the people the member referred. page max 1000, perPage max 100
GET/api/affiliate/referral/{id}
One referral with its earnings summary
GET/api/affiliate/referral/node
The member's own node, with the referrals above and below it
POST/api/affiliate/referral/analysis
Chart and KPI data for the member's referral analytics
GET/api/affiliate/reward
The member's rewards, with the condition each came from. Supports the standard list filters
POST/api/affiliate/reward/{id}/claim
Claims one reward into a wallet. Enforces the withdraw_affiliate KYC feature and the payout threshold

Admin endpoints

GET/api/admin/affiliate/dashboardpermission: access.affiliate
Dashboard metrics, charts, the pending queue and stalled affiliates

Referrals

GET/api/admin/affiliate/referralpermission: view.affiliate.referral
List all referrals
GET/api/admin/affiliate/referral/{id}permission: view.affiliate.referral
Read one referral
POST/api/admin/affiliate/referralpermission: create.affiliate.referral
Create a referral by hand. Rejects self-referral and any referred user who already has a sponsor
PUT/api/admin/affiliate/referral/{id}permission: edit.affiliate.referral
Update a referral
PUT/api/admin/affiliate/referral/{id}/statuspermission: edit.affiliate.referral
Approve or reject. ACTIVE places the referral in the tree, REJECTED removes it and re-parents its children
PUT/api/admin/affiliate/referral/statuspermission: edit.affiliate.referral
Bulk status change
DELETE/api/admin/affiliate/referral/{id}permission: delete.affiliate.referral
Soft-delete a referral. Add force=true to remove it permanently, restore=true to bring it back
DELETE/api/admin/affiliate/referralpermission: delete.affiliate.referral
Bulk delete
GET/api/admin/affiliate/referral/{id}/nodepermission: view.affiliate.referral
Tree node for one referral

Conditions

GET/api/admin/affiliate/conditionpermission: view.affiliate.condition
List conditions, each with its overlap analysis and effective percentage rate
GET/api/admin/affiliate/condition/{id}permission: view.affiliate.condition
Read one condition
POST/api/admin/affiliate/conditionpermission: create.affiliate.condition
Create a condition: program, firesOn, schedule, interval, target, friend's share and minAmount are all accepted. Judged on the whole row; refuses an active condition that overlaps an existing one unless acknowledgeOverlap is true
PUT/api/admin/affiliate/condition/{id}permission: edit.affiliate.condition
Update a condition (everything except name). Judged on the whole stored row with the patch laid over it. Enforces the maximum commission rate on PERCENTAGE rewards, and on the friend's share
DELETE/api/admin/affiliate/condition/{id}permission: edit.affiliate.condition
Delete a condition that is switched off and has no reward written under it, soft-deleted ones included. 409 for an active one or one that has paid
PUT/api/admin/affiliate/condition/{id}/statuspermission: edit.affiliate.condition
Enable or disable a condition. Enabling is refused with a 409 when it competes with an active one
PUT/api/admin/affiliate/condition/statuspermission: edit.affiliate.condition
Bulk enable or disable

A condition that has paid cannot be deleted, because the reward table cascades on the condition: deleting it would delete every reward written under it, claimed ones included, and with them the record of what the affiliates were paid. The delete takes a row lock on the condition and does the count and the delete in one transaction, so a reward written a millisecond earlier is counted.

Applications

GET/api/admin/affiliate/applicationpermission: view.affiliate.referral
List applications and approved affiliates with the user attached
POST/api/admin/affiliate/applicationpermission: edit.affiliate.referral
Add an approved affiliate by hand, naming the user by id or by email. A user who already has a standing is moved to APPROVED. The affiliate is notified
PUT/api/admin/affiliate/application/statuspermission: edit.affiliate.referral
Decide one to 100 applications with one shared reason (up to 500 characters): status APPROVED, REJECTED or PENDING. Stamps who decided and when, and notifies the applicant of a decision that changed
DELETE/api/admin/affiliate/application/{id}permission: delete.affiliate.referral
Remove one standing. The row is deleted, which frees the personal code. Referrals and rewards are untouched
DELETE/api/admin/affiliate/applicationpermission: delete.affiliate.referral
Remove a selection of standings. This is the data table's Delete Selected

Rewards

GET/api/admin/affiliate/rewardpermission: view.affiliate.reward
List all rewards
GET/api/admin/affiliate/reward/{id}permission: view.affiliate.reward
Read one reward
POST/api/admin/affiliate/rewardpermission: create.affiliate.reward
Create a reward by hand against a referrer and a condition
PUT/api/admin/affiliate/reward/{id}permission: edit.affiliate.reward
Update a reward amount or its claimed flag. Moves no money
PUT/api/admin/affiliate/reward/{id}/statuspermission: edit.affiliate.reward
Mark a reward claimed or unclaimed. Moves no money
PUT/api/admin/affiliate/reward/statuspermission: edit.affiliate.reward
Bulk claimed-status change
DELETE/api/admin/affiliate/reward/{id}permission: delete.affiliate.reward
Soft-delete a reward
DELETE/api/admin/affiliate/rewardpermission: delete.affiliate.reward
Bulk delete

Reward payout

GET/api/admin/affiliate/reward-tokenpermission: access.affiliate.settings
The active ecosystem tokens a reward can be paid in, and the saved payout mode, token and its market, fixed and effective USD prices

The four payout settings are saved through the platform settings endpoint like every other key, and only a Super Admin can change them. It refuses a token that is not an active ecosystem token.

Core endpoints the add-on relies on

Two routes outside /api/affiliate take part, and both belong to core.

GET/api/public/referrer/{refCode}
Looks a referrer up for the sign-up form. The reference is a user id or a personal code in any case; answers the username, avatar and, for a code, the code in capitals. A code that resolves to nobody and an id that resolves to nobody both answer the same 404
POST/api/auth/register
Registration reads the ref field, a user id or a personal code, once, when the account is created. A reference that names nobody creates the account with no referrer

Database tables

Six tables, all prefixed mlm_.

mlm_referral

Who referred whom. referrerId, referredId, status of PENDING / ACTIVE / REJECTED. Soft-deleting.

Two unique indexes, and they matter:

  • referredId is unique. A user can be somebody's referral exactly once, ever. Sponsors cannot be re-assigned, and a soft-deleted row still holds the slot.
  • (referrerId, referredId) is unique. A relationship cannot be duplicated.

A row where referrerId equals referredId is a self-referral: it marks the top of a chain and is created automatically for members who need a tree root. The upline walk stops when it reaches one.

mlm_affiliate

Who is an affiliate: one row per member who applied, was added by an admin or chose a code. userId is unique and code is unique (null repeats), so a member has one standing and a code has one holder. status is PENDING, APPROVED or REJECTED; code is 3 to 32 characters of A–Z, 0–9, _ and -, stored in capitals; message is what the applicant wrote and reviewNote what the reviewer wrote back (up to 500 characters); reviewedAt and reviewedBy stamp the decision, the latter a plain id with no foreign key so it outlives the admin.

It is not soft-deleting, on purpose: a soft-deleted row would keep its user and its code, so a revoked affiliate could never apply again and their code could never be given to anyone else. Revoking only marks the row REJECTED (the code stays reserved to that member and stops resolving); deleting the standing removes the row. On an install that has not switched on applications, every member counts as approved without a row; a row is created the first time somebody chooses a code.

mlm_referral_condition

The commission rules. Unique on name. Not soft-deleting and carrying no timestamps. Conditions are edited in place; one that is switched off and has never paid can be deleted, and one that has paid cannot, because the reward table cascades on it.

Notable columns: type (16-value enum driving the ledger scan), reward and rewardType, rewardWalletType / rewardCurrency / rewardChain (what the reward is worth, and where it lands unless every reward is paid in the reward token), minAmount (a floor on each transaction), status, and period (DAILY by default; settable on the condition).

The program and schedule columns: program (AFFILIATE by default, or REFERRAL), scheduleType (LIFETIME by default, INTERVAL or ONE_TIME), intervalDays (30) and intervalCount (0, no limit) for INTERVAL, targetAmount (0) — what a referred member's activity must add up to in one window —, referredReward (0) — the friend's share, in the same type and unit as reward — and firesOn, the event a condition is paid at when that is not its own name. They arrive with one schema sync; a row from before it reads as an Affiliate Program, every-time condition with no target and no share, which is exactly what it always was.

mlm_referral_reward

Earned commissions. referrerId, conditionId, reward (a DOUBLE), currency and walletType (what the reward is paid in), isClaimed, and sourceId. Soft-deleting.

currency and walletType are set when the reward is written: the condition's, or the reward token and ECO when rewards are paid in a token. The claim pays exactly that, so a reward never changes currency after it is earned. Rows written before Core 6.8.6 are filled from their condition by the update's seeder; a row still NULL there is paid in its condition's currency.

sourceId is unique and is the whole of the duplicate protection. The hourly evaluator writes condition_referrer_referred_period, or condition_referrer_referred_I<window> for an every-N-days condition; a one-time condition writes <condition>:once:<referred>; the multi-level event path appends :L1, :L2 and so on; the friend's share appends :RF to the referrer's key; and a condition that rides on an event it does not own writes <event key>:<condition id>. MySQL permits multiple NULLs in a unique index, so rewards created without one are unaffected — those fall back to a 60-second, same-amount duplicate check instead.

Deleting a reward keeps its sourceId, so the evaluator will not recreate it.

mlm_binary_node and mlm_unilevel_node

Tree placement. Both are unique on referralId — one node per referral — and neither carries timestamps.

mlm_binary_node holds parentId, leftChildId and rightChildId. mlm_unilevel_node holds only parentId and allows any number of children.

Both payout paths walk mlm_referral.referrerId. These two tables exist to draw the network diagram. Deleting rows from them corrupts the member-facing tree and changes nobody's earnings.

The scheduled job

One job, registered only while the mlm extension is enabled and deregistered within a scheduler cycle when you switch it off — no restart needed either way.

Property Value
Name processMlmReferralConditions
Title Process MLM Referral Conditions
Category mlm
Interval Hourly
Writes Reward rows, and empty payout wallets for referrers
Reads Active conditions, active referrals, which referrers are approved affiliates, referred users' wallets and completed transactions

It never moves money. It creates reward rows and, alongside a new reward, the referrer's payout wallet if they do not have one — so a member is never blocked at claim time for want of a wallet row.

Each run evaluates both the current window and the one just completed — calendar periods for an every-time condition, a referred member's N-day windows for an every-N-days one — and reads each one-time condition's unsettled members since they joined. That double pass is why the deterministic sourceId matters: without it, the re-scan would pay everything twice. It skips the event-paid conditions, and the Referral Program's conditions while applications are not required.

Its log is the addon's best diagnostic. It names each reward it creates, each condition it skipped and why, currencies it could not price, and the case where none of the referred users hold any wallet at all. Configuration warnings are rate-limited to roughly every four hours so one misconfiguration across forty conditions produces one line rather than eighty.

Settings the engine reads

All stored as text in the platform settings table.

Key Read by
affiliateMlmSystem Structure selection — DIRECT, BINARY, UNILEVEL
affiliateBinaryLevels Level count under BINARY (2–7)
affiliateBinaryLevel1 … affiliateBinaryLevel7 Per-level share under BINARY
affiliateUnilevelLevels Level count under UNILEVEL (2–7)
affiliateUnilevelLevel1 … affiliateUnilevelLevel7 Per-level share under UNILEVEL
affiliateRequireApproval Whether new referrals start PENDING
affiliateApplicationRequired Whether a member must be approved to be an affiliate. Absent or anything but true is the open program
affiliateShowCommissions Whether the rates are shown to everyone. Absent means shown; only an explicit false hides them
affiliateMaxCommissionRate Ceiling on PERCENTAGE condition rewards
affiliatePayoutThreshold Minimum unclaimed balance before claiming, in USD
affiliateRewardPayoutMode CONDITION (each condition's currency) or TOKEN (one ecosystem token)
affiliateRewardToken The ecosystem token code rewards are paid in
affiliateRewardTokenPriceSource MARKET, FIXED or MARKET_OR_FIXED
affiliateRewardTokenUsdPrice USD per token for the fixed price

Two legacy keys are still read as a fallback when the current ones are absent: mlmSystem (the structure) and mlmSettings (a JSON blob containing both level configurations, with the values stored as strings). Saving the settings screen once writes the current keys, which then take precedence.

Full descriptions and consequences: Programme settings.

Where commissions are triggered from

Event-driven conditions are fired by the code that processed the activity, in core and in other addons. Which means: an addon you do not own cannot pay its commission, and disabling an addon stops its rules firing without disabling the conditions themselves. Those conditions stay active and stay invisible to members, because the members' rates page filters by enabled extension.

The one exception to "conditions belong to addons" is the core set — deposits, spot and binary trading, and investments — which is always available.