Glad the cleanup resolved your immediate issue. Let me address all three aspects of your original problem comprehensively:
REST API Endpoint Configuration:
The /invoices/post endpoint in ICS 2021 has a known issue with transaction state management. When implementing your integration, add these headers to your API calls:
X-Transaction-Timeout: 300
X-Force-Unique-Check: false
X-Clear-Pending-On-Retry: true
The timeout ensures long-running posts don’t leave orphaned pending records, while the unique check parameter limits scope as James mentioned.
Unique Invoice Numbers in Payload:
Your payload structure should include both the invoice number and a transaction ID for idempotency. Structure it like:
{
"invoiceNumber": "INV-2025-0345",
"transactionId": "uuid-generated-value",
"companyCode": "1000",
"fiscalYear": "2025"
}
The transactionId allows safe retries without creating duplicates even if the initial call partially succeeded.
Error Message Handling:
The duplicate invoice error you encountered occurs because CloudSuite checks three tables: posted invoices (AR_INVOICE), pending transactions (AR_PENDING), and the audit trail (AR_HISTORY). Your invoices were stuck in AR_PENDING with PROCESSING status, which is why they didn’t appear in normal AR screens but triggered duplicate errors.
Prevention Strategy:
Implement a scheduled job (daily at 2 AM) that runs the transaction cleanup utility automatically. Set it to clear any transactions stuck in PROCESSING status for more than 6 hours. Also, configure your middleware to include retry logic with exponential backoff - if an invoice post fails, wait 30 seconds before retry, then 60, then 120. This prevents rapid-fire retries that can create multiple pending entries.
Additionally, enable API logging in CloudSuite (System Configuration > API Management > Enable Transaction Logs) to track the full lifecycle of each invoice post. This helps diagnose whether failures occur during validation, posting, or commit phases.
For monitoring, set up alerts when the AR_PENDING table exceeds 50 records, as this indicates a systemic issue with transaction completion rather than isolated failures.