Sync of Historic Orders
When a user installs my app, I want to give the admin the option to pull the last 30 historical orders into the app so that there is some data to work with within the user interface.
They will trigger this from a button inside the app admin.
I have a route available that can perform this for me, and I'm using the following code.
The code seems to run and the result of the call is:
However, no records are populated into the
shopifyOrder table. My development store definitely has orders in it that predate installation of the app.
Am I missing something?
TIA!24 Replies
Hello,
Are any of the orders created within the last 60 days? Shopify will only send you order data for the last 60 days unless you have the read_all_orders (needs special permissions) scope
yes i have some from 4th, 5th November for example. Thanks
Could you please share the URL of the app so that I can take a closer look?
its https://storescore.gadget.app/ (the new code is in my dev env in /api/routes/POST-initial-score-boost.js) the store id i am trying to sync from is 91171586396
Sidebar: Might I ask why you made a route for this instead of just initiating the sync from the frontend?
just in case i want to trigger same from elsewhere - but i dont mind moving it if its problematic.
Also a sidenote: You need to await reply statements in routes or you risk the chance that your application crashes with error "Cannot set headers for..."
Not problematic, just wondering
yeah im a noob š
Which store have you been testing with? I see 6 stores in your database
91171586396
"store-score-potato"
Mind if I try running the sync? I just ran a query with Postman and you should be getting orders
sure thing!
I see:

So the issue is that you need to fill out more optional fields in the PCDA form or remove that field from your order model
A better message to follow:

ah - does that mean the whole sync fails becuase of that?
You'll need to remove the address fields as well
Yes
Since you're trying to sync fields that you don't have access to. We build the sync payload based on the fields that you have in your schema
this is very helpful - thanks for the pointer - i will get on that!
No problem!
What has thrown me is that webhook events (in dev and production) still get new order data saved to the database and those fields are in the schema. I guess the sync is more explicitly asking for the data rather than getting a payload
Yeah, that makes sense. Shopify simply doesn't send the fields in question
thanks again - you guys crush it every time!
Do you like this answer?
ā
ive got a follow up question on this - sorry!
I deleted the
statusPageUrl field and the sync started to work. I do need elements of the billingAddress json packet (and i do have permission for the customer name and email address) - so on a webhook i get billing address populated as:
now with the shopifySync i get more fields - with the protected ones nulled out (which is fine)
BUT, other fields i would expect to sync dont seem to - of particular important is currentTotalPrice which is just returned null by the sync. In face all pricing columns (which are populated fine by the WebHooks) are null.
Any ideas?
@Chocci_Milk - the sync is :
const syncResult = await api.shopifySync.run({
shopifySync: {
domain: shop.domain,
shop: { _link: shopId },
models: ["shopifyOrder"],
syncSince: sixtyDaysAgo,
syncSinceBy: "created_at",
},
});
actually i have understood another point - not all feilds get synced - but i can pull those i need later direct from shopify via graphql -- all good