← back to Dw Signup Fulfillment

verification/tk10836/verify-auto-discounts.js

31 lines

'use strict';
const config = require('../../lib/config');
const shop = config.SHOP_DOMAIN, token = config.SHOPIFY_FULFILLMENT_TOKEN;
const Q = `
{
  automaticDiscountNodes(first: 30) {
    nodes {
      id
      automaticDiscount {
        __typename
        ... on DiscountAutomaticApp { title status startsAt endsAt createdAt
          appDiscountType { functionId title appKey } }
        ... on DiscountAutomaticBasic { title status startsAt endsAt }
      }
    }
  }
}`;
(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 }) });
  const j = await r.json();
  if (j.errors) { console.error(JSON.stringify(j.errors)); return; }
  for (const n of j.data.automaticDiscountNodes.nodes) {
    const a = n.automaticDiscount;
    console.log([n.id, a.__typename, a.title, a.status,
      a.appDiscountType ? `fn=${a.appDiscountType.functionId}` : '',
      a.createdAt || ''].join(' | '));
  }
})().catch(e => { console.error('ERR', e.message); process.exit(1); });