← back to Shopify Sample Shipping

expand-general-free.mjs

11 lines

import fs from 'node:fs';
import {TOKEN, SHOP} from '../designerwallcoverings/scripts/lib/shopify.mjs';
const path='/admin/api/2026-07/shipping_zones/28691464304/weight_based_shipping_rates/668938600499.json';
const body={weight_based_shipping_rate:{id:668938600499,name:'Free Shipping (No Tracking)',price:'0.00',weight_low:null,weight_high:5.0}};
const before=JSON.parse(fs.readFileSync(new URL('./verification/rest-zones.json',import.meta.url))).shipping_zones.find(z=>z.id===28691464304).weight_based_shipping_rates.find(r=>r.id===668938600499);
if(before.weight_high!==0.5)throw Error('Unexpected live baseline: '+JSON.stringify(before));
const r=await fetch(`https://${SHOP}${path}`,{method:'PUT',headers:{'X-Shopify-Access-Token':TOKEN,'Content-Type':'application/json'},body:JSON.stringify(body),signal:AbortSignal.timeout(30000)});
const text=await r.text();let j;try{j=JSON.parse(text)}catch{throw Error(JSON.stringify({status:r.status,body:text.slice(0,500)}));}if(!r.ok||j.errors)throw Error(JSON.stringify({status:r.status,body:j}));
fs.writeFileSync(new URL('./verification/general-free-expanded.json',import.meta.url),JSON.stringify({before,after:j.weight_based_shipping_rate},null,2)+'\n');
console.log(JSON.stringify({before,after:j.weight_based_shipping_rate}));