Prompt
invoice sync API multi currency audit trail
Latest observation
Nov 4, 2026
OpenAI APIWeb search: off
Here’s a solid checklist/spec for an Invoice Sync API with multi-currency support and an audit trail.
Core requirements
1) Invoice sync
- Create, update, delete, and fetch invoices via API
- Support idempotent sync operations
- Handle external system invoice IDs
- Track sync status:
pendingsyncedfailedconflict
2) Multi-currency
Each invoice should store:
- Invoice currency: original currency of the invoice
- Base currency: company/accounting default currency
- Exchange rate used at sync time
- Converted amounts in base currency
Recommended fields:
currency_code— e.g.USD,EURamount_totalamount_taxamount_discountbase_currency_codebase_amount_totalexchange_rateexchange_rate_sourceexchange_rate_timestamp
3) Audit trail
Every sync action should create an immutable audit record.
Track:
- Who/what triggered the sync
- Timestamp
- Action type
- Old values vs new values
- Source system
- Request ID / correlation ID
- Result status
- Error details if failed
Recommended audit fields:
audit_identity_type=invoiceentity_idaction=create | update | delete | syncbefore_stateafter_stateperformed_bysource_systemrequest_idtimestampstatuserror_codeerror_message
Suggested API endpoints
Sync invoice
POST /api/v1/invoices/sync
Request
{
"external_invoice_id": "INV-10045",
"source_system": "erp_x",
"currency_code": "EUR",
"amount_total": 1200.50,
"amount_tax": 240.10,
"base_currency_code": "USD",
"exchange_rate": 1.0832,
"exchange_rate_timestamp": "2026-11-04T10:15:00Z",
"customer_id": "cus_123",
"line_items": [
{
"description": "Consulting",
"quantity": 10,
"unit_price": 120.05
}
]
}
Response
{
"invoice_id": "inv_789",
"sync_status": "synced",
"currency_code": "EUR",
"base_currency_code": "USD",
"base_amount_total": 1298.48,
"audit_id": "aud_456"
}
Get invoice
GET /api/v1/invoices/{invoice_id}
Get audit trail
GET /api/v1/invoices/{invoice_id}/audit
Sync status
GET /api/v1/invoices/{invoice_id}/sync-status
Important design considerations
Currency precision
- Store monetary values with fixed precision, e.g.
DECIMAL(18,6) - Avoid floating-point types
Rounding rules
- Define:
- rounding mode
- rounding per line item vs invoice total
- tax rounding behavior
Exchange rate policy
- Use rate at time of sync
- Persist the rate and source so calculations are reproducible
- Consider support for:
- manual rate override
- daily market rate
- rate provider metadata
Idempotency
- Use
Idempotency-Keyheader for sync calls - Prevent duplicate invoice creation on retries
Conflict handling
- If external invoice changes after local edits:
- reject
- overwrite
- merge
- Record conflict details in audit trail
Minimal database model
invoices
idexternal_invoice_idsource_systemcurrency_codeamount_totalamount_taxbase_currency_codebase_amount_totalexchange_ratesync_statuscreated_atupdated_at
invoice_audit_logs
idinvoice_idactionbefore_jsonafter_jsonsource_systemperformed_byrequest_idstatuserror_messagecreated_at
Example audit event
{
"audit_id": "aud_456",
"entity_type": "invoice",
"entity_id": "inv_789",
"action": "sync",
"source_system": "erp_x",
"performed_by": "integration-user",
"request_id": "req_abc123",
"timestamp": "2026-11-04T10:15:12Z",
"status": "success",
"before_state": {
"amount_total": 1100.00,
"currency_code": "EUR"
},
"after_state": {
"amount_total": 1200.50,
"currency_code": "EUR"
}
}
If you want, I can turn this into one of these:
- OpenAPI/Swagger spec
- Database schema
- Node.js / Python API implementation
- Detailed audit/event design