How to implement affiliate system through api

Hi,
How to implement affiliates system through API. I got affiliate id when someone clicks on unique links. When user signups from this link then I saved an entry in the Referral table with the affiliate id and when I click on the referral partner tab under contact then it will list me current referral details(see attached image ).

But when I go to ledger report it will do not show me any entry (also no entry for product sold).
Is there any way to implement this through API?