← back to Dw Signup Fulfillment
verification/tk10836/verify-sample-ship.js
34 lines
'use strict';
const config = require('../../lib/config');
const shop = config.SHOP_DOMAIN, token = config.SHOPIFY_FULFILLMENT_TOKEN;
const Q = `
query($q: String!) {
orders(first: 25, query: $q, sortKey: CREATED_AT, reverse: true) {
nodes {
name createdAt discountCodes
subtotalPriceSet { shopMoney { amount } }
totalShippingPriceSet { shopMoney { amount } }
shippingLine { title originalPriceSet { shopMoney { amount } } discountedPriceSet { shopMoney { amount } } }
lineItems(first: 20) { nodes { title quantity originalUnitPriceSet { shopMoney { amount } } } }
}
}
}`;
(async () => {
const r = await fetch(`https://${shop}/admin/api/2024-10/graphql.json`, {
method: 'POST', headers: { 'X-Shopify-Access-Token': token, 'Content-Type': 'application/json' },
body: JSON.stringify({ query: Q, variables: { q: 'created_at:>2026-06-01' } }) });
const j = await r.json();
if (j.errors) { console.error(JSON.stringify(j.errors)); return; }
const rows = j.data.orders.nodes;
console.log('order | sampleOnly | items | subtotal | shipTitle | shipCharged | codes');
for (const o of rows) {
const li = o.lineItems.nodes;
const sampleOnly = li.length > 0 && li.every(x => Number(x.originalUnitPriceSet.shopMoney.amount) <= 5);
console.log([o.name, sampleOnly ? 'SAMPLE-ONLY' : 'mixed', li.length,
o.subtotalPriceSet.shopMoney.amount,
o.shippingLine ? o.shippingLine.title : '-',
o.totalShippingPriceSet.shopMoney.amount,
(o.discountCodes||[]).join(',') || '-'].join(' | '));
}
})().catch(e => { console.error('ERR', e.message); process.exit(1); });