Skip to main content

How do I avoid duplicate Avalara tax transactions at period close?

Avalara's documentCode is reserved only once committed — reusing an uncommitted or voided code is allowed, but reusing a committed one returns DocumentCodeConflict. Generate codes deterministically from an invoice number, not a random value, and retry failed calls with that same code, so a network retry can't silently create a second committed transaction.

Zuny FesterBy Zuny Fester, Head of Operations and Marketing
Reviewed by Zuny Fester
Published Last reviewed Editorial policy

Part of the finance integrations guide.

Root cause of duplicatesA retry after a timeout or dropped response generates a new documentCode instead of reusing the original
What AvaTax actually reservesA committed document's code, per company and document type — not every code ever sent
Where this shows upTwo AvaTax transactions for what should be one invoice, at the exact same period
The fixDerive documentCode deterministically from the invoice/order, and retry with the same code, not a new one
Related riskAn uncommitted transaction from a failed first attempt can be voided or left uncommitted rather than retried blind

Why retries are the usual cause

A duplicate tax transaction at period close almost never comes from someone deliberately creating a transaction twice. It comes from a network timeout, a dropped response, or a retry policy that doesn't know whether the first call actually succeeded on Avalara's side before failing on the client side. If that retry logic generates a fresh documentCode for the second attempt — instead of resending the same one — AvaTax has no way to recognize it as the same transaction, and both can end up committed.

What Avalara's DocumentCodeConflict error actually tells you

AvaTax reserves a documentCode once its transaction is committed, scoped to a company and document type. Sending the same code again after that point returns a DocumentCodeConflict error rather than silently overwriting or duplicating anything — which is actually the safety net that catches the retry problem, provided the retry logic reuses the original code instead of generating a new one on failure. A code that was never committed (an errored or voided attempt) can be reused without conflict, which is deliberate: it's what makes a genuine retry-with-the-same-code pattern work correctly.

The fix, concretely

Derive documentCode from something already unique and deterministic in the source system — an invoice number, an order ID — rather than a randomly generated value created fresh on each call. On a failed or ambiguous response, retry with that same code; if AvaTax returns DocumentCodeConflict on the retry, that's confirmation the original attempt actually succeeded, not a new error to work around. Reserve void or delete actions for transactions genuinely meant to be cancelled, not as a routine way to clear a code before reissuing it.

Next step

Map the finance workflow with the most exposure and prove the automation path.

Bring the invoice, contract, payment reconciliation, or customer finance workflow you have to defend at audit. Loopfour can map the trigger, controls, integrations, and approval loop.

Book a workflow review

Worked example

A timeout that almost created two committed transactions for one invoice

A workflow calls AvaTax to commit a SalesInvoice transaction for invoice INV-4821, using documentCode=INV-4821. The request reaches Avalara and commits successfully, but the response times out before the client receives it. The retry logic, built to generate a fresh code on every attempt, sends a second request with documentCode=INV-4821-retry — Avalara has no way to know this is meant to be the same transaction, and commits it too. Result: two committed transactions, double tax liability recorded, for one invoice. The fix: retry logic that reuses documentCode=INV-4821 on the second attempt instead. Avalara returns DocumentCodeConflict, correctly signaling the first attempt already succeeded — no duplicate, and the workflow can treat the conflict as confirmation rather than failure.

Frequently Asked Questions

No — it's the safety mechanism, not the problem. The actual bug is retry logic that generates a new documentCode instead of reusing the original one, which is what lets a duplicate slip past that safety net in the first place.

Less directly — an uncommitted transaction's code isn't reserved the same way, so reusing it won't trigger a conflict. But it also means an uncommitted duplicate can sit unnoticed rather than being caught, which is a related but distinct risk covered on the sibling page about uncommitted transactions.

No — that's the opposite of the fix. A fresh code on every attempt is exactly what removes AvaTax's ability to recognize a retry as the same transaction and defeats the conflict check entirely.

Sources

Related