splitwise / api-docs

API documentation for the Splitwise API.
http://dev.splitwise.com
28 stars 16 forks source link

How to create a reimbursement transaction #60

Closed fwouts closed 2 years ago

fwouts commented 2 years ago

Is it possible to create a reimbursement transaction with the Splitwise API?

I usually do this by entering a negative amount in the web app (it doesn't work on Android), but if I try to enter a negative amount in a createExpense API call, it's rejected. I imagine there's another endpoint for that, but perhaps it's not publicly exposed?

Thank you :)

fwouts commented 2 years ago

I can answer this myself after checking network logs in the browser: creation_method: "reimbursement" 🎉

jas14 commented 2 years ago

@fwouts , you'll find that setting that parameter doesn't affect expense calculations. In general, the Splitwise API doesn't allow negative costs or shares.

If you'd like to enter a reimbursement, you'll have to calculate an "inverse expense," if you will. In a typical expense for $X with one payer and K users, the payer paid $X, and everyone owed $X/K. In a reimbursement, everyone paid $X/K (which you can put in the paid field), and the person who received the reimbursement owed $X. That is, you can think of a "reimbursement" expense of $X as a normal expense of $X with the paid and owed fields reversed.

Hope this helps!