Skip to main content
QuickBooks frequently needs to paginate responses to avoid timeouts and other issues. Usually this would require tracking iterator metadata and making multiple requests to QuickBooks.

Auto-pagination to the rescue

A list query QuickBooks can page is paged for you. Send it with no paging parameters, and QuBe Sync asks QuickBooks for 100 records at a time (25 when you ask for include_line_items or include_linked_txns): Every page QuickBooks returns is immediately sent to your webhook_url as it arrives, all with the same id. What you send decides how the answer comes back:
One answer can be at most 4 MB as the Web Connector sends it, about 3 MB of qbXML. A larger one isn’t kept: the request ends error with error_type response_too_large (why). Pages keep answers well under that. If a page of records with many lines still reaches it, ask for a smaller max_returned.
Some lists QuickBooks doesn’t page at all, such as accounts, terms, classes and employees. Those always answer in one go. A large one is best narrowed with its filters, such as a modified-date range.
Using the stream_query workflow guarantees pages get delivered in the correct order, even when there are weird network latencies, your endpoint goes down, or any other situation that might disrupt the delivery order.

Pages on demand

Each queued request also has a links.pages URL, which returns the pages answered so far, oldest first, each with its own iteration_state. It answers 20 of them at a time: ask for more with page, and up to 100 at a time with page_size. meta.total_pages says how many pages of them there are. Each one carries its whole response_xml, so keep page_size small for a large query.

Listing your connections

GET /api/v2/connections answers 20 connections a page, oldest first, with the same page and page_size (up to 100) and meta.total_pages. v1’s GET /api/v1/connections takes the same two parameters, and there they are optional: send neither and it answers every connection in one go with no meta, exactly as it always has, so an existing v1 integration sees no change.

An initial import

New QuickBooks connections usually require bringing over large lists of various record types in bulk. You can use the plain paginated API (above), or a workflow: A run needs its webhook_url — without one it’s refused, 422 webhook_url_required — and your endpoint should answer within 5 seconds: a page your app can’t take is retried for about an hour with the same delivery_id, and the run waits in the meantime. Each page names its kind (customer, item_service, …), so one handler takes them all. Installing pull_changes installs the stream_query it runs once per kind. Copy the template into your own workflow to send different fields, or even run each page through a workflow of its own. See Sending your app data, which has the payload.

Tips

1-200 records per page keeps each round trip quick on a slow machine. Transactions with many lines are heavier than list records.
After the first full import, filter on the modified date so each sync only fetches what changed. A list query (customers) takes from_modified_date directly; a transaction query (invoices) takes modified_date_range_filter[from_modified_date]. See Making requests.For the next sync’s starting point, keep the newest time_modified you received, exactly as it came, and send it back as the filter. QuickBooks includes that second, so that record arrives again. Don’t convert it to UTC. During daylight saving time QuickBooks labels local times with the standard offset (-08:00 for Pacific daylight time) and reads the filter the same way. So its own value finds what it should, while a UTC time from your own clock reaches up to an hour further back and repeats some records.The pull_changes workflow does all this for you, including which records were deleted (which a modified-date filter can’t find). QuickBooks reports deletions only for the record types you ask about, so list every type your app keeps: a pull that names invoice and sales_order won’t tell you about a deleted payment. A record merged into another in QuickBooks arrives as deleted. The one it was merged into keeps its list_id, and isn’t reported as changed.
QuickBooks doesn’t keep invoice numbers (ref_number) unique. It accepts a new invoice with a number another invoice already has, and a voided invoice keeps its number (with its amounts at zero).If your app requires unique invoice numbers, expect an import to bring in numbers you already hold, and decide what a clash means for you: keep both, link them by txn_id, or skip one and log it. Importing voided invoices too, as void, stops your app handing out their numbers again.

Handling far edge cases

In most cases the following is overkill, but for those who need it: If you’re not using a workflow like stream_query, and you can’t make your webhook processing idempotent (or it’s computationally expensive), and you need to definitively know that a query is 100% done, you may want to plan around edge cases that result from network latencies or your endpoint being unreachable:
Rarely, conditions external to QuBe Sync can cause pages to arrive out of order (page 4 can land before page 3), or a retried delivery to arrive twice. Key on page_request_id plus state. A page whose state is retryable isn’t final: the same page_request_id arrives again later as response_received, error, timed_out or discarded. See What to do with each state.
Every page’s webhook has the same request id from the initial query and its own page_request_id: Process each page in the background as it arrives. You don’t need to wait for the last one. The done page (or max_sandbox_iterations_reached in a sandbox) is the last sent, and its page number tells you how many pages there are. The import is complete once you’ve handled every page from 1 to that number, not when the done page arrives since it could theoretically arrive before earlier pages. Keep the set of page numbers you’ve handled. A handler that stores only the last iteration_state it saw can end on continue.
In a sandbox app, an iteration stops after 4 pages. The last page’s iteration_state is then max_sandbox_iterations_reached instead of done. Production apps page through everything.

If the session ends partway

If that session ends before the last page (QuickBooks closes, the Web Connector is stopped, or the connection drops), QuickBooks can’t pick up where it left off. The next page’s webhook then has state: error, with error_type: quickbooks_connection_error and a user_message saying so. Queue the query again to get the rest. It starts from the first page, so upsert returned records by their connection, kind and list_id or txn_id rather than create duplicates.