Skip to content
Desktop Accounting API

Idempotency and safe retries

Networks drop. When a create times out, check whether QuickBooks recorded it before making another write. Reuse the same idempotency key for retries within its seven-day retention period. During that period, a completed or uncertain write is not sent again. After the key expires, the API can treat it as new; verify the earlier outcome before retrying old work.

Send an Idempotency-Key header on any POST or DELETE:

Terminal window
IDEMPOTENCY_KEY=$(uuidgen) # one new key per invoice; resend the same value on every retry
curl https://api.desktopaccountingapi.com/v1/quickbooks-desktop/invoices \
-H "Authorization: Bearer $DAAPI_SECRET_KEY" \
-H "Daapi-End-User-Id: eu_01j9..." \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-H "Content-Type: application/json" \
-d '{"customerId":"80000012-1730312001","lines":[{"itemId":"80000003-1730311000","quantity":2,"rate":"125.00"}]}'
  • Use a new random value, such as a UUID, for each logical operation, and reuse the same value for every retry of that operation.
  • 1 to 255 printable ASCII characters. Anything else returns 400 IDEMPOTENCY_KEY_INVALID.
  • Keys are scoped to the project and end user (or to the project for platform calls such as creating an end user) and kept for 7 days.
  • Reusing a key with a different request (method, path, end user or body) returns 422 IDEMPOTENCY_KEY_REUSED. A key always means one request.

The SDKs generate a key for every write and reuse it across their automatic retries. Pass your own key when the retry happens outside the SDK, for example in a job queue that may run the same job twice:

import { DesktopAccountingApi } from "@desktopaccountingapi/quickbooks-desktop";
const qb = new DesktopAccountingApi().forEndUser("eu_01j9...");
// Derive the key from your own record so a re-run of the job reuses it.
const invoice = await qb.qbd.invoices.create(
{
customerId: "80000012-1730312001",
refNumber: "1042",
lines: [{ itemId: "80000003-1730311000", quantity: 2, rate: "125.00" }],
},
{ idempotencyKey: "order-5541-invoice" },
);
console.log(invoice.id);
State of the first request The repeat
Rejected by validation (a 4xx before queueing) Not stored. The repeat is processed as new.
Queued, or sent and waiting for QuickBooks Attaches to the same request and waits for its result (sync), or returns 202 with the same request (async). It never adds a second queue entry.
Finished: succeeded, or failed after QuickBooks answered The stored status and body, with Daapi-Idempotent-Replayed: true.
Ended before it was sent (canceled, expired, timed out in the queue, connection offline) The key is released and the repeat runs as a new request, linked by previousRequestId. This is safe because nothing reached QuickBooks.
Rejected because QuickBooks was briefly busy (QBD_TRANSIENT_ERROR) The key is released and the repeat runs as a new request, linked by previousRequestId. This is safe because QuickBooks applied nothing. The SDKs retry it this way automatically.
outcome_unknown The same QBD_WRITE_OUTCOME_UNKNOWN error. The write is never sent again.

A repeat that arrives while the original is still queued, with a shorter Daapi-Timeout-Seconds, never cancels the original. It gets its own 504 QBD_REQUEST_TIMEOUT and the original keeps running.

The request resource records a write’s outcome, and write errors carry it in the error object. A successful typed endpoint normally returns the record or action result. Batch results also state each member’s outcome:

outcome Meaning Safe to retry?
applied QuickBooks confirmed the change. No need.
not_applied The change certainly did not happen: validation failed, it was never sent, or QuickBooks returned an error. Yes, after fixing the cause if retryable is false.
pending Sent to QuickBooks, result not known yet. No. Read the request with GET /v1/requests/{id}?waitSeconds=60.
unknown Sent, and the result could not be confirmed. No. See below.
not_applicable A read. Reads are always safe to retry.

Once a write reaches QuickBooks, we never send it again on our own.

A write becomes outcome_unknown when it reached QuickBooks but no answer came back: the customer’s computer lost its network mid-request, the Web Connector was closed, the session broke, or the response could not be read. The API returns 502 QBD_WRITE_OUTCOME_UNKNOWN (type OUTCOME_UNKNOWN_ERROR), the request resource shows status: "outcome_unknown", and the SDKs raise OutcomeUnknownError without retrying.

While a write is uncertain, the connection holds later writes back (waitingReason: "write_recovery_pending") so QuickBooks’ record of that write stays intact. Reads keep flowing.

Every write carries a message set ID derived from its request ID, recorded on the request (quickbooks.messageSetId). The hold on later writes ends when that Web Connector session ends. The uncertain write itself stays outcome_unknown: we never guess, and we never send it again.

Check the company file yourself before writing again:

  1. For a create whose schema supports externalId, look for that UUID. If you omit it, the API supplies a UUID and returns it in the uncertain-write error’s details. Search all relevant pages and date ranges. Other creates need resource-specific identifiers.
  2. Or look it up by refNumber or name. Invoices, bills and checks usually carry your reference number; list objects have unique names.
  3. If you find the record, use it. A missing search result alone does not prove that the write failed. Keep the original key and ask support to help resolve the request before attempting another create.

When automatic recovery is on for the connection and the API later finds the create in QuickBooks, GET /v1/requests/{id} shows recovered: true and the record’s QuickBooks ID in recoveredObjectId. See Recovered writes.

  • Let the SDK retry. It only retries what is safe and reuses the key.
  • For raw HTTP, send an Idempotency-Key on every POST and DELETE, and reuse it on retry.
  • Retry only when retryable is true (Daapi-Should-Retry: true), with backoff, honoring Retry-After.
  • On pending, read the request. On unknown, verify. Never resend either.
  • Keep keys for longer than your longest retry window, but no longer than 7 days; after that the API treats the key as new.