Fix: SP-API Marketplace ID Scoping + Dashboard Card Data Consistency #20
Open
opened 2026-06-29 08:36:09 +00:00 by rob
·
1 comment
Labels
Clear labels
Amazon SP-API
bug
Doing
eBay API
FBA Restock
FBA Restock
FBA Restock
fulfillment
Planning
Planning
Planning
Planning
Planning
prod
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
QA
shipstation
shipstation
No Label
Amazon SP-API
Milestone
No items
No Milestone
Projects
Clear projects
No project
eStack Sprint Board
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: rob/estack-laminas#20
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
All Amazon channel accounts in eStack are correctly configured with the right
marketplace IDs. However, the SP-API
getOrderssync is not passing theMarketplaceIdsparameter on API calls. This causes every sync job to pull allorders from the entire regional endpoint rather than the specific marketplace it
is responsible for. The result is that whichever channel's sync runs first claims
all orders for that region, leaving other channels with little or no data.
This is confirmed by auditing the channel accounts table — every marketplace ID
is correct — and by observing that Amazon Canada (24 orders in eStack) vs Seller
Central (239 orders, 30 days) shows exactly the pattern of a race condition where
the US sync claims the NA order pool first on most cycles.
Root Cause
Amazon SP-API uses three regional endpoints, each serving multiple marketplaces
under a single Selling Partner credential:
sellingpartnerapi-na.amazon.comsellingpartnerapi-eu.amazon.comsellingpartnerapi-fe.amazon.comWithout
MarketplaceIdsscoped per call,getOrdersreturns orders from allmarketplaces accessible on that endpoint. Since US, CA, and MX share one NA
credential, a US sync with no filter pulls CA and MX orders too — and imports
them all as Amazon US. Same pattern applies across all five EU channels.
Confirmed Channel Account Configuration on Prima Instance
All nine accounts are correctly configured. No account setup changes are needed.
ATVPDKIKX0DERA3GNDTLYQCCHJPA2EUQ1WTGCTBG2A3GNDTLYQCCHJPA1AM78C64UM0Y8A3GNDTLYQCCHJPA1F83G8C2ARO7PA6B2MIY3HRTZQA1PA6795UKMFR9A6B2MIY3HRTZQA13V1IB3VIYZZHA6B2MIY3HRTZQAPJ6JRA9NG5V4A6B2MIY3HRTZQA1RKKUPIHCS9HSA6B2MIY3HRTZQA39IBJ37TRP1C6AK231R381GL07Confirmed Discrepancies (30-Day Period)
These gaps are entirely explained by the missing MarketplaceIds filter:
CA orders are not missing from eStack — they exist but are attributed to Amazon
US. The same pattern applies to DE, FR, IT, ES orders appearing under Amazon GB.
The Orders by Country dashboard card confirms this: Germany shows 639 orders and
France 75 despite neither having orders attributed to their own channel — those
are EU marketplace orders imported under the GB channel and broken out by buyer
shipping address.
Fix 1 — Add MarketplaceIds to every getOrders call (Priority 1 — required)
This is the core fix. One parameter added to every
getOrdersAPI call, readingthe marketplace ID from the channel account record.
Current behavior (broken):
Required behavior:
What to check:
getOrdersis calledMarketplaceIdsis added to every call without exceptionExpected outcome:
buyers shipping to those countries from correctly attributed channels
Fix 2 — Historical order re-attribution migration (Priority 1 — ship with Fix 1)
Once Fix 1 is deployed, new orders will land in the correct channel. However,
all existing orders in the database are misattributed. Since SP-API returns
MarketplaceIdon every order object and this value is already stored on eachorder record, re-attribution is a single database operation.
This migration must run immediately after Fix 1 deploys, before the next
sync cycle, to prevent double-importing already-migrated orders.
Van to verify:
orderstable storesmarketplace_idfrom the SP-API responsechannel_accountstable has amarketplace_idcolumn (confirmed from UI)re-attributed to CA
Fix 3 — AU timezone boundary (Priority 2)
Amazon AU (A39IBJ37TRP1C6) is under-counting by ~21 orders over 30 days (~12%).
AU is the only Far East endpoint channel and is not affected by the multi-
marketplace bleed issue — its gap is caused by date boundary calculation.
SP-API returns all timestamps in UTC. Amazon.com.au operates in AEST (UTC+10)
or AEDT (UTC+11). If eStack's dashboard window calculations apply any local
timezone offset when constructing
CreatedAfter/CreatedBeforeparameters,the boundary will be misaligned for AU, losing approximately 1–2 days of orders
across the window edges.
What to check:
CreatedAfteris always calculated asNOW_UTC - N dayswith nolocal timezone conversion applied on top
toggle query (7d, 30d, MTD) — both must use the same UTC-based boundary
Fix 4 — Pending order inclusion decision (Priority 2 — requires Rob input)
Seller Central's "All orders" tab includes
Pendingstatus orders. Canada'sSeller Central view shows recent orders with "Pending — Awaiting payment
verification" prominently. If eStack excludes Pending from sync, real-time
counts will always lag Seller Central, most visibly on CA and AU where recent
orders frequently sit in Pending state.
Option A — Match Seller Central (recommended):
Include Pending in sync and dashboard counts. eStack totals become directly
comparable to Seller Central at any point in time.
OrderStatuses to include:
Option B — Operational orders only:
Exclude Pending. Dashboard shows only actionable orders. Counts will always
be lower than Seller Central by design.
Rob to confirm Option A or B before Van implements.
Once confirmed, the chosen OrderStatuses set must be defined in a single
constant or config value and used consistently across every
getOrderscalland every dashboard query. No per-channel variation.
Fix 5 — % Sales by Channel pie card label (Priority 3)
The pie card and Orders by Channel card show contradictory percentages for the
same 30-day period. With the orders correctly attributed after Fixes 1 and 2,
the order counts will change significantly — run the pie card audit after
re-attribution is complete to determine whether the divergence persists.
If it does:
the Orders by Channel card and investigate remaining divergence
Fix 6 — Resolve Unknown = 256 in Orders by Country (Priority 3)
256 orders over 30 days have no country attribution in the Orders by Country
card. After re-attribution (Fix 2), this number may change — audit after
migration before investigating further.
If Unknown remains significant:
marketplace country as a fallback attribution
Fix 7 — Add last-synced timestamp to dashboard channel rows (Priority 4)
Amazon US currently shows "Synced 574 days ago" in Store Settings but this
staleness is invisible on the dashboard itself. A merchant looking at the
dashboard has no way to know the data is 18 months old.
Add a "Last synced X ago" indicator under each channel name in the Orders by
Channel card. Style with
--es-mutedfor normal recency. For last syncDisplay-only change, no SP-API work required.
Files to Check
getOrderscallMarketplaceIdsparam reading from channel accountorderstableReproduction Steps
domain. Orders with
@marketplace.amazon.de,@marketplace.amazon.fretc.confirm EU bleed into the GB channel
dates — consistent with sync race condition, not missing data
Sequencing — Critical
Fixes 1 and 2 must ship together in the same deployment:
Do not run the migration before Fix 1 is deployed — the next sync would
re-misattribute orders immediately after the migration completes.
Priority
P1 — Critical. Every Amazon channel in eStack has incorrect order counts
and attribution. Canada is showing 10% of actual orders. GB is showing 85% more
orders than it should. The fix is a single parameter addition to one API call,
plus a one-time database migration. These should be the next items Van works on.
Fix 3 (AU timezone) and Fix 4 (Pending — pending Rob's decision) can ship in
the same PR or a follow-up. Fixes 5–7 are lower priority and can follow
separately.