6:58 Gruner Solutions

← Field notes

ApparelMagic API · 5 min

Why page 2 of your ApparelMagic query is page 1 again

A pagination bug that never shows up until the day it costs you today's orders.

ApparelMagic retired page-number pagination on February 13, 2023. The only supported method now is a cursor, pagination[last_id]. If your code still sends pagination[page_number], ApparelMagic ignores it without complaint and hands back page 1 again.

Our code sent the page number for months. It never failed in production, because every real query fit on one page. One retailer's open orders had never filled a page.

Why it matters on your busiest day

ApparelMagic returns the oldest records first. Once a query outgrows one page, a loop that keeps receiving page 1 sees only the oldest records. At scale, the orders it would miss are today's. The job would report that it processed everything it found, and it would be telling the truth.

The fix

One function now does every multi-page read. It follows last_id and stops on any of four things:

  • a page with no rows
  • a response with no last_id
  • a page cap
  • a cursor that fails to advance

The last one is the signature of a cursor being ignored. We report it as truncation, not as the end of the data. Anything that depends on having the full list, such as a duplicate check, treats a truncated list as no list and stops.

Two filter traps that look the same

A filter ApparelMagic ignores returns unfiltered data. Ask for that retailer's recent orders with a date filter it does not honor and you get page 1 of everything, oldest first: our distribution-center shipments from 2021. They match nothing, and the job reports a quiet day. Now any query with a date cutoff throws if a single row comes back older than the cutoff.

A filter ApparelMagic accepts but cannot match returns 200 and zero rows. A date written as YYYY-MM-DD HH:MM:SS did exactly that for us. Zero rows passes any staleness check by default, so we also assert that a record we know should be in the result actually is.

How to test yours

Walk an unfiltered list at page size 10, so it genuinely spans pages. Compare the total rows against the count of distinct ids. If they differ, your pagination is repeating pages.

Running reports or syncs against ApparelMagic? Run that test this week. If the numbers disagree, I can help.