diff --git a/auth.js b/auth.js index b9a05d5..d7b8ec4 100755 --- a/auth.js +++ b/auth.js @@ -137,8 +137,6 @@ router.get('/auth/callback', async (req, res) => { } res.redirect(`https://admin.shopify.com`); - - res.send('Access token saved. You may close this window.'); } catch (err) { const errMsg = err.response?.data || err.message; log(shop, `❌ OAuth error: ${JSON.stringify(errMsg)}`); diff --git a/fulfillmentService.js b/fulfillmentService.js index c06b3df..a257266 100755 --- a/fulfillmentService.js +++ b/fulfillmentService.js @@ -66,7 +66,22 @@ async function createFulfillmentService(shop, accessToken) { } // The fulfillment service has its own Shopify-managed location — use it as fallback - const serviceFallbackLocationId = fulfillmentService?.location?.id || null; + // Shopify sometimes returns location: null from the create mutation — re-query if so + let serviceFallbackLocationId = fulfillmentService?.location?.id || null; + if (!serviceFallbackLocationId) { + try { + log(shop, `🔍 [FulfillmentService] location null from mutation — re-querying fulfillment services...`); + const reQueryResp = await client.post('', { + query: `query { fulfillmentServices(type: THIRD_PARTY) { id handle location { id name } } }`, + }); + const svcs = reQueryResp.data?.data?.fulfillmentServices || []; + const matched = svcs.find(s => s.handle === 'data4autos-distribution') || svcs[0] || null; + serviceFallbackLocationId = matched?.location?.id || null; + log(shop, `📍 [FulfillmentService] Re-query location: ${serviceFallbackLocationId}`); + } catch (reQErr) { + log(shop, `⚠️ [FulfillmentService] Re-query failed: ${reQErr.message}`); + } + } log(shop, `📍 [FulfillmentService] Service location (fallback): ${serviceFallbackLocationId}`); // ── Step 2: Try to create a custom named location ────────────────────────