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.
const syncResult = await api.shopifySync.run({
shopifySync: {
domain: shop.domain,
shop: { _link: shopId },
models: ["shopifyOrder"],
syncLast: 30,
syncLastBy: "created_at",
},
});
const syncResult = await api.shopifySync.run({
shopifySync: {
domain: shop.domain,
shop: { _link: shopId },
models: ["shopifyOrder"],
syncLast: 30,
syncLastBy: "created_at",
},
});
The code seems to run and the result of the call is:
{
"__typename": "ShopifySync",
"createdAt": "2025-11-17T18:30:20.801Z",
"domain": "xyz.myshopify.com",
"errorDetails": null,
"errorMessage": null,
"force": false,
"id": "926",
"models": [
"shopifyOrder"
],
"shopId": "9117000000",
"state": "running",
"syncLast": 30,
"syncLastBy": "created_at",
"syncSince": null,
"syncSinceBy": null,
"updatedAt": "2025-11-17T18:30:20.801Z"
}
{
"__typename": "ShopifySync",
"createdAt": "2025-11-17T18:30:20.801Z",
"domain": "xyz.myshopify.com",
"errorDetails": null,
"errorMessage": null,
"force": false,
"id": "926",
"models": [
"shopifyOrder"
],
"shopId": "9117000000",
"state": "running",
"syncLast": 30,
"syncLastBy": "created_at",
"syncSince": null,
"syncSinceBy": null,
"updatedAt": "2025-11-17T18:30:20.801Z"
}
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
Chocci_Milk
Chocci_Milk•4w ago
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
Lozz
LozzOP•4w ago
yes i have some from 4th, 5th November for example. Thanks
Chocci_Milk
Chocci_Milk•4w ago
Could you please share the URL of the app so that I can take a closer look?
Lozz
LozzOP•4w ago
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
Chocci_Milk
Chocci_Milk•4w ago
Sidebar: Might I ask why you made a route for this instead of just initiating the sync from the frontend?
Lozz
LozzOP•4w ago
just in case i want to trigger same from elsewhere - but i dont mind moving it if its problematic.
Chocci_Milk
Chocci_Milk•4w ago
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
Lozz
LozzOP•4w ago
yeah im a noob šŸ™‚
Chocci_Milk
Chocci_Milk•4w ago
Which store have you been testing with? I see 6 stores in your database
Lozz
LozzOP•4w ago
91171586396 "store-score-potato"
Chocci_Milk
Chocci_Milk•4w ago
Mind if I try running the sync? I just ran a query with Postman and you should be getting orders
Lozz
LozzOP•4w ago
sure thing!
Chocci_Milk
Chocci_Milk•4w ago
I see:
No description
Chocci_Milk
Chocci_Milk•4w ago
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
Chocci_Milk
Chocci_Milk•4w ago
A better message to follow:
No description
Lozz
LozzOP•4w ago
ah - does that mean the whole sync fails becuase of that?
Chocci_Milk
Chocci_Milk•4w ago
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
Lozz
LozzOP•4w ago
this is very helpful - thanks for the pointer - i will get on that!
Chocci_Milk
Chocci_Milk•4w ago
No problem!
Lozz
LozzOP•4w ago
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
Chocci_Milk
Chocci_Milk•4w ago
Yeah, that makes sense. Shopify simply doesn't send the fields in question
Lozz
LozzOP•4w ago
thanks again - you guys crush it every time!
Gizmo
Gizmo•4w ago
Do you like this answer? ​
Lozz
LozzOP•3w ago
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:
{
"name": "Lawrence Williams",
"company": null,
"country": "United Kingdom",
"province": "England",
"last_name": "Williams",
"first_name": "Lawrence",
"country_code": "GB",
"province_code": "ENG"
}
{
"name": "Lawrence Williams",
"company": null,
"country": "United Kingdom",
"province": "England",
"last_name": "Williams",
"first_name": "Lawrence",
"country_code": "GB",
"province_code": "ENG"
}
now with the shopifySync i get more fields - with the protected ones nulled out (which is fine)
{
"zip": null,
"city": "Macclesfield",
"name": "Lawrence Williams",
"phone": null,
"company": null,
"country": "United Kingdom",
"address1": null,
"address2": null,
"latitude": null,
"province": "England",
"last_name": "Williams",
"longitude": null,
"first_name": "Lawrence",
"country_code": "GB",
"province_code": "ENG"
}
{
"zip": null,
"city": "Macclesfield",
"name": "Lawrence Williams",
"phone": null,
"company": null,
"country": "United Kingdom",
"address1": null,
"address2": null,
"latitude": null,
"province": "England",
"last_name": "Williams",
"longitude": null,
"first_name": "Lawrence",
"country_code": "GB",
"province_code": "ENG"
}
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

Did you find this page helpful?