Skip to main content

Suppliers API

Like customers, suppliers are managed through the sync engine. All create/update/delete operations go through POST /api/v1/sync/push.

Supplier Record Schemaโ€‹

{
"id": "supp-uuid-001",
"store_id": "store-uuid-001",
"name": "Al-Nour Wholesale",
"phone": "967711223344",
"contact_person": "Ibrahim Hassan",
"address": "Sana'a, Al-Hasabah District",
"notes": "Delivers every Tuesday",
"created_at": "2026-07-01T08:00:00Z",
"updated_at": "2026-07-01T08:00:00Z",
"deleted_at": null
}
FieldTypeDescription
idUUID stringUnique identifier (generated on device)
store_idUUID stringStore this supplier belongs to
namestringSupplier business or person name
phonestringContact number with country code
contact_personstringName of the representative
addressstringPhysical address
notesstringInternal notes
created_atISO 8601Creation timestamp
updated_atISO 8601Last modified timestamp
deleted_atISO 8601 or nullSoft delete timestamp

Creating a Supplier via Syncโ€‹

POST /api/v1/sync/push
Authorization: Bearer <token>
X-Device-ID: <device_uuid>

{
"device_id": "550e8400-e29b-41d4-a716-446655440000",
"items": [
{
"id": "sq-uuid-supp-001",
"entity_type": "supplier",
"entity_id": "supp-uuid-001",
"operation": "create",
"payload": {
"id": "supp-uuid-001",
"store_id": "store-uuid-001",
"name": "Al-Nour Wholesale",
"phone": "967711223344",
"contact_person": "Ibrahim Hassan",
"address": "Sana'a, Al-Hasabah District",
"notes": "Delivers every Tuesday",
"created_at": "2026-07-01T08:00:00Z",
"updated_at": "2026-07-01T08:00:00Z",
"deleted_at": null
},
"version": 1,
"created_at": "2026-07-01T08:00:00Z"
}
]
}

Supplier Transaction Schemaโ€‹

Supplier transactions use entity_type: "supplier_transaction":

{
"id": "stxn-uuid-001",
"store_id": "store-uuid-001",
"supplier_id": "supp-uuid-001",
"type": "purchase",
"amount": 50000.00,
"description": "Weekly stock delivery",
"invoice_number": "INV-2026-0721",
"reference": "STXN-20260721-001",
"date": "2026-07-21",
"created_at": "2026-07-21T10:00:00Z",
"updated_at": "2026-07-21T10:00:00Z",
"deleted_at": null
}
FieldValues
type"purchase" (you bought from them) or "payment" (you paid them)
amountAlways positive
invoice_numberSupplier's invoice reference (optional)

Push Example โ€” Recording a Purchaseโ€‹

{
"device_id": "550e8400-e29b-41d4-a716-446655440000",
"items": [
{
"id": "sq-uuid-stxn-001",
"entity_type": "supplier_transaction",
"entity_id": "stxn-uuid-001",
"operation": "create",
"payload": {
"id": "stxn-uuid-001",
"store_id": "store-uuid-001",
"supplier_id": "supp-uuid-001",
"type": "purchase",
"amount": 50000.00,
"description": "Weekly stock delivery",
"invoice_number": "INV-2026-0721",
"reference": "STXN-20260721-001",
"date": "2026-07-21",
"created_at": "2026-07-21T10:00:00Z",
"updated_at": "2026-07-21T10:00:00Z",
"deleted_at": null
},
"version": 1,
"created_at": "2026-07-21T10:00:00Z"
}
]
}

Balance Calculationโ€‹

The server does not store a current_balance field for suppliers. Instead, balance is always computed:

SELECT
COALESCE(SUM(CASE WHEN type = 'purchase' THEN amount ELSE 0 END), 0)
- COALESCE(SUM(CASE WHEN type = 'payment' THEN amount ELSE 0 END), 0)
AS current_balance
FROM supplier_transactions
WHERE supplier_id = $1 AND deleted_at IS NULL;

The client caches this computed balance in the local SQLite suppliers table's current_balance column and recalculates it after every pull.