Debt API
Created: January 27, 2025This documentation provides comprehensive information about the Debt API endpoints, including customer debt tracking, invoice management, and payment processing capabilities.
All Debt API endpoints require authentication and store context. Ensure you include the
x-store-id header and a valid Bearer token for all requests.Overview
The Debt API provides comprehensive debt management capabilities:- Customer Debt Tracking: Retrieve all customers with outstanding debt amounts and invoice counts
- Invoice Management: View customer invoices with payment status and outstanding amounts
- Payment Processing: Make payments to specific invoices or distribute payments across multiple invoices
- Payment History: Track payment entries and allocations for audit purposes
Endpoint Details
Base URL:https://joptic.jethings.com
Required Headers
Get Customers with Debt
GET/debt/customers
Retrieve a list of all customers who have outstanding debt, including their total due amounts and the number of unpaid invoices.
Requires Authentication: Bearer token in Authorization headerRequires Header:
x-store-id
Success Response
Status Code:200 OK
Response Fields
| Field | Type | Description |
|---|---|---|
customers | array | Array of customers with outstanding debt |
customers[].id | string | Unique customer identifier |
customers[].firstName | string | null | Customer’s first name |
customers[].lastName | string | null | Customer’s last name |
customers[].userName | string | null | Customer’s username or email |
customers[].totalDueAmount | number | Total outstanding debt amount across all invoices |
customers[].numberOfInvoices | number | Count of invoices with outstanding balances |
Notes
- Only customers with at least one invoice that has an outstanding balance are included
- The
totalDueAmountis calculated as the sum of all outstanding amounts across all unpaid invoices - Invoices are considered unpaid if
totalPaid < ttc(total tax included) - Deleted customers and deleted invoices are automatically excluded
Example Requests
Get Customer Invoices
GET/debt/customers/:customerId/invoices
Retrieve all invoices for a specific customer, including payment status and outstanding amounts. Optionally filter to show only invoices with outstanding balances.
Requires Authentication: Bearer token in Authorization headerRequires Header:
x-store-id
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | string | ✅ Yes | The ID of the customer |
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
onlyOutstanding | boolean | No | false | If true, returns only invoices with outstanding balances |
Success Response
Status Code:200 OK
Response Fields
| Field | Type | Description |
|---|---|---|
customer | object | Customer information |
customer.id | string | Customer identifier |
customer.firstName | string | null | Customer’s first name |
customer.lastName | string | null | Customer’s last name |
customer.userName | string | null | Customer’s username or email |
invoices | array | Array of customer invoices |
invoices[].id | string | Invoice identifier |
invoices[].ttc | string | Total tax included (invoice total) |
invoices[].totalPaid | number | Total amount paid towards this invoice |
invoices[].outstandingAmount | number | Remaining unpaid amount (ttc - totalPaid) |
invoices[].createdAt | string | Invoice creation timestamp (ISO 8601) |
invoices[].storeId | string | null | Store ID associated with the invoice |
invoices[].isPosInvoice | boolean | Whether this is a POS invoice |
invoices[].doc_status | string | Document status (e.g., “Submitted”, “Paid”) |
Error Responses
404 Not Found - Customer not foundNotes
- Invoices are sorted by creation date (oldest first)
- When
onlyOutstanding=true, only invoices whereoutstandingAmount > 0are returned - The
outstandingAmountis calculated asttc - totalPaid - Deleted invoices are automatically excluded
Example Requests
Pay Customer Debt
POST/debt/customers/:customerId/pay
Make a payment towards a customer’s total debt. The payment is automatically distributed across the customer’s unpaid invoices, starting with the oldest invoice first. If the payment amount exceeds the total outstanding debt, the remaining amount is returned.
Requires Authentication: Bearer token in Authorization headerRequires Header:
x-store-id
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | string | ✅ Yes | The ID of the customer |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
amount | number | ✅ Yes | Payment amount (must be positive, minimum 0.01) |
Request Body Example
Success Response
Status Code:200 OK
Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates if the payment was successful |
paymentsCreated | array | Array of payment entries and allocations created |
paymentsCreated[].paymentEntry | object | Payment entry record |
paymentsCreated[].paymentAllocation | object | Payment allocation linking payment to invoice |
paymentsCreated[].invoiceId | string | ID of the invoice that was paid |
paymentsCreated[].amountPaid | number | Amount paid towards this invoice |
remainingAmount | number | Remaining payment amount if payment exceeded total debt |
Special Cases
No Unpaid Invoices:Error Responses
400 Bad Request - Invalid payment amountNotes
- Payments are distributed across invoices in chronological order (oldest first)
- Each invoice is paid up to its outstanding amount before moving to the next invoice
- If a payment amount exceeds the total outstanding debt, the
remainingAmountfield indicates the excess - Invoices without a
storeIdare skipped during payment distribution - Each payment creates a
paymentEntryand a correspondingpaymentAllocationrecord
Example Requests
Pay Invoice
POST/debt/customers/:customerId/invoices/:invoiceId/pay
Make a payment towards a specific invoice. The payment amount cannot exceed the outstanding balance of the invoice. If the invoice is already fully paid, a success response is returned with no payment created.
Requires Authentication: Bearer token in Authorization headerRequires Header:
x-store-id
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | string | ✅ Yes | The ID of the customer |
invoiceId | string | ✅ Yes | The ID of the invoice to pay |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
amount | number | ✅ Yes | Payment amount (must be positive, minimum 0.01) |
Request Body Example
Success Response
Status Code:200 OK
Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates if the payment was successful |
message | string | null | Optional message (e.g., “Invoice is already fully paid”) |
paymentEntry | object | null | Payment entry record (null if invoice already paid) |
paymentAllocation | object | null | Payment allocation record (null if invoice already paid) |
amountPaid | number | Actual amount paid (may be less than requested if invoice has less outstanding) |
remainingOutstanding | number | Remaining outstanding amount after payment |
Special Cases
Invoice Already Fully Paid:Error Responses
400 Bad Request - Invalid payment amount or missing storeIdNotes
- The payment amount is automatically capped at the invoice’s outstanding amount
- If the requested amount exceeds the outstanding balance, only the outstanding amount is paid
- The
amountPaidfield reflects the actual amount applied to the invoice - If an invoice is already fully paid, the endpoint returns success with
amountPaid: 0and no payment records created - The invoice must have a valid
storeIdfor the payment to be processed
Example Requests
Important Notes
Payment Processing
Payment Distribution
Payment Distribution
When paying customer debt (not a specific invoice), payments are distributed across invoices in chronological order (oldest first). Each invoice is paid up to its outstanding amount before moving to the next invoice.
Payment Amount Limits
Payment Amount Limits
- Payment amounts are automatically capped at the outstanding balance
- For customer debt payments, if the amount exceeds total debt, the excess is returned in
remainingAmount - For invoice payments, if the amount exceeds outstanding, only the outstanding amount is paid
Payment Records
Payment Records
Each successful payment creates:
- A
paymentEntryrecord tracking the payment transaction - A
paymentAllocationrecord linking the payment to the specific invoice - Both records are returned in the response for audit purposes
Invoice Validation
Invoice Validation
- Invoices must belong to the specified customer
- Invoices must have a valid
storeIdfor payments to be processed - Deleted invoices are automatically excluded from all operations
Debt Calculation
Outstanding Amount
Calculated as:
ttc - totalPaidoutstandingAmount = invoiceTotal - paymentsMadeTotal Debt
Sum of all outstanding amounts across all invoices for a customer
totalDebt = Σ(outstandingAmount)Data Filtering
- Only non-deleted customers and invoices are included in results
- Invoices with
ttc(total tax included) ofnullare excluded - Customers with no outstanding debt are excluded from the customers list
- Invoices are sorted by creation date (oldest first) for payment distribution
Summary
1
Get Customers with Debt
Use
GET /debt/customers to retrieve all customers who have outstanding balances2
View Customer Invoices
Use
GET /debt/customers/:customerId/invoices to see all invoices and their payment status3
Make Payment
Choose between:
- Pay specific invoice:
POST /debt/customers/:customerId/invoices/:invoiceId/pay - Pay customer debt:
POST /debt/customers/:customerId/pay(distributes across invoices)
4
Verify Payment
Check the response to confirm payment amounts and remaining balances