QHR Developers

Settle several loans the employees paid back

POST/hr_loans/settle
Needs a read & write tokenSettle loans (record a repayment) loan/settleRequires feature loanNot available in Claudehr_loans.settle_batch

Records that one or more loans were paid back outside payroll, all on the same repaid_on. All or nothing: if any loan cannot be settled, none is, and the refusal names that loan. A direct loan is settled for its whole amount; a payroll loan for what its installments have not collected yet, and its remaining installments are cancelled so nothing more is deducted from pay. Without accounting approval it is final at once: the loan becomes settled and a received payment is recorded on repaid_on (today by default, never in the future). In a company connected to Qoyod the loan becomes pending_settlement and nothing is recorded until an accountant approves; the answer is then 202 instead of 200.

When to use: to settle everything an employee owes at once (e.g. before they leave), or several employees' repayments in one go.

Prerequisites: loan_ids from hr_loans.for_employee (loans with can_settle: true). The token's owner must be an employee.

Side effects: for each loan a received payment and cancelled installments, and the repayment (loan.repaid) sent to Qoyod accounting when connected. Recorded in the audit log. Cannot be undone and acts on many loans, so it is not offered to Claude.

Irreversible operation

This operation cannot be undone and can affect the whole company. Double-check the ids before you call it. For safety it is never offered through Claude.

Before you call this

You will need ids that come from these operations:

Parameters

NameInTypeDescriptionExample
Accept-LanguageheaderstringLanguage of messages and translated labels. English when omitted.
Allowed values: ar, en
ar

Request body

application/json

FieldTypeDescription
loan_idsRequiredarray<integer>Loans to settle, from hr_loans.for_employee.
repaid_onstring (date)Date the employee repaid; today when omitted. Not in the future, not before the payout.

Response

200 Settled: `accounting_mode: legacy`, every loan `settled`.

FieldTypeDescription
accounting_modestringlegacy (settled now) or approval (waiting for the accountant).
recordsarray<object>Each loan after the settlement.
records[].idintegerLoan id.
records[].referencestringLoan reference, e.g. LON-0042.
records[].statusstringStatus: pending (waiting for HR), pending_accounting (HR approved, an accountant in Qoyod is deciding), approved (lent, nothing repaid yet), repaying (installments being collected), pending_settlement (a settlement waits for the accountant), settled (paid back), rejected or cancelled.
Allowed values: pending, pending_accounting, approved, repaying, pending_settlement, settled, rejected, cancelled
records[].channelstringHow the money moves, chosen by HR at approval: payroll (paid out on a payslip and repaid in monthly installments deducted from pay) or direct (paid out and repaid in one payment outside payroll). Null until approved.
Allowed values: payroll, direct, null
records[].currencystringThe employee's pay currency, ISO code.
records[].settlement_amountstringAmount settled: what was still outstanding.
records[].settlement_datestring (date)Date the money was repaid.
records[].repaid_onstring (date)Repaid on.
records[].installments_voidedintegerFuture installments cancelled (0 until the accountant approves).
records[].paymentsarray<object>Payments behind a direct loan: the payout (paid) and the repayment (received). Always empty for a payroll loan, whose money moves on the payslip.
records[].payments[].idintegerPayment id.
records[].payments[].referencestringPayment reference.
records[].payments[].kindstringpaid (to the employee) or received (from them).
records[].payments[].purposestringdisbursement or repayment.
records[].payments[].datestring (date)Payment date.
records[].payments[].amountstringAmount. Decimal string.
records[].payments[].currencystringThe employee's pay currency, ISO code.
records[].accountingobjectWhat Qoyod accounting says about the loan (its settlement while one is in play, else its payout). Every field is null when the company is not connected.
records[].accounting.gatestringloan when an accountant must approve this loan, else none.
records[].accounting.statestringDelivery state: queued, sending, pending_approval, posted, declined, failed…
records[].accounting.event_idstringAccounting event id.
records[].accounting.reason_codestringWhy it was declined or held.
records[].accounting.reasonstringThe reason in words.
records[].accounting.decided_atstringWhen the accountant decided.
records[].accounting.decided_bystringThe accountant (email Qoyod sent).
records[].accounting.resubmit_allowedbooleanWhether a declined loan may be approved again.
records[].accounting.journal_entrystringQoyod journal entry number once posted.

Errors

HTTPCodeMeaningHow to fix
401token_missingNo Authorization: Bearer … header, or it is malformed.Send Authorization: Bearer qhr_… with the full token.
401token_invalidThe token is unknown or wrong, or its owner's account is locked.Check the token was copied in full, or create a new one in QHR › Settings › API & Integrations.
401token_expiredThe token is past its expiry date.Create a new token.
401token_revokedThe token was revoked by its owner or an admin, or the owner was removed from the company (which revokes all their tokens).Create a new token, or ask your admin. If the owner was removed, they must be re-invited to the company first.
401tenant_inactiveThe company account is suspended.Contact QHR support.
403token_read_onlyThis token can only read; the operation makes changes.Use a token created with "Allow changes".
403forbiddenThe token owner's role lacks the permission this operation needs.Ask an admin to grant the permission shown on this operation (x-permission).
403employee_inactiveThe token owner's employee record is not active.HR must reactivate the employee record.
403tenant_access_revokedThe token's owner is no longer an active member of this company. Rare: removing a member normally revokes their tokens, which answers 401 token_revoked instead.The owner must be re-invited to the company, then create a new token. If the owner is still a member, contact QHR support.
422not_settleableThe loan is not approved or repaying. loan_id and reference name the loan.Settle only loans with can_settle: true in hr_loans.for_employee.
422already_pending_settlementA settlement of the loan already waits for the accountant. loan_id and reference name the loan.Wait for the accountant's decision in Qoyod.
422nothing_outstandingNothing is left to repay on the loan. loan_id and reference name the loan.Leave that loan out.
422payout_not_deliveredA payroll loan whose payout has not reached the employee yet. loan_id and reference name the loan.Pay the payroll run that carries the payout first, or cancel the loan.
422installment_in_flightAn installment sits on a payroll run that has not been paid (named in error). loan_id and reference name the loan.Pay or revert that payroll run first.
422repaid_before_disbursementrepaid_on is before the loan was paid out. loan_id and reference name the loan.Send a repaid_on on or after the payout date.
422repaid_in_futurerepaid_on is after today. loan_id and reference name the loan.Record the repayment once the money has arrived.
422repaid_on_unreadablerepaid_on is not a date.Send repaid_on as YYYY-MM-DD.
422no_loansloan_ids is empty.Send at least one loan id from hr_loans.for_employee.
422unknown_loansSome ids name no loan; they are listed in loan_ids. Nothing was settled.Refresh the list with hr_loans.for_employee and send existing ids.
422employee_requiredThe token's owner has no employee record, and a settlement is recorded in the name of the employee who made it.Use a token created by a person who is an employee here.
This endpoint can also return the errors that can happen on any endpoint →402 / 412 / 425 entitlement_blocked · 429 rate_limited · 500 internal_error

See the full error catalogue →