- For: treasurers
- You get: a Refunds tab with each money-out bank line still to reconcile, a dropdown of the payments it could refund, and a button that records the ones you pick
- Time: about twenty minutes the first time, then a few minutes each month
- Scopes:
accounting:read,accounting:writeandpayments:read. Addaccounting.people:readto see who each bank line paid, andpayments.people:readto see which family each payment came from.
1. Try the requests
Paste these into a terminal to see the demo group’s bank inbox and payments:id, date, amount and the bankAccountId. A refund is recorded against a payment (GET /payments: a Direct Debit collection, or a cycle marked paid by hand), or against a payment request paid by hand (GET /payment-requests with status=paid_manually), which has no payment.
2. Add the script
Make a Google Sheet for it, choose Extensions → Apps Script, delete what is there, paste the script below and choose Save. Then add a script propertySCOUTWORKS_API_KEY with your key, in Project Settings → Script Properties.
Code.gs
3. List the lines
Choose listRefunds and press Run. The first time, Google asks you to allow the script to reach an outside service. The Refunds tab fills with each money-out line in the bank inbox. For each one that is a refund, pick the payment it refunds in Refund of. Leave the others empty: a card payment to the Scout Shop is not a refund. Amount to record starts at the whole bank line. Make it smaller when one transfer refunds part of a payment.4. Try it on one line
1
Pick one
Choose a payment for one line only. Leave the rest empty.
2
Record it
Choose recordRefunds and press Run. Result says Recorded and the refund’s id.
3
Check it in Scoutworks
The line has left the Bank Inbox, and the payment shows as refunded on its payments page.
4
Undo it, if it is wrong
Send
DELETE /refunds/manual/{id} with the refund’s id from Result. The line goes back to the inbox. To record it again, clear Result and Key on that row, fix the payment or amount, and run it again. Or leave it, if it was right.5. Record the rest
Pick a payment for each refund and choose Run on recordRefunds. A row that already has a result is skipped, so run it as often as you like. Choose listRefunds again next month: the lines you recorded have left the inbox.Why nothing is recorded twice
Each row’s first try makes anIdempotency-Key and keeps it in Key. If the network drops after Scoutworks recorded it, the next run sends the same key and gets the same answer back, not a second refund. And a line already matched has left the inbox, so Scoutworks refuses it.
If something goes wrong
409 over_refund: the amount is more than the bank line, or more than is left to refund on that payment (it may have been refunded already). ReadGET /refundswith the payment’s id aspaymentIdto see what is already refunded.400 invalid_request: usually a line that is not money out, was not imported from a statement, or has already been reconciled, or a payment that is not your group’s. The message says which.409 period_closed: the bank line is dated in an accounting year that is closed.403 insufficient_scope: recording needsaccounting:writeandpayments:read, as well asaccounting:read.409 source_lockedwhen undoing: only a refund the API recorded can be unlinked through the API. Unmatch it in the Bank Inbox instead.
payments.people:read, parents’ names. Share it only with the treasurer and the trustees who need it.
See Errors for every code.