const fs = require("fs"); const path = require("path"); const env = fs.readFileSync(path.join(__dirname, "..", ".env"), "utf8"); const TOKEN = env.match(/BASELINKER_API_TOKEN\s*=\s*(\S+)/)[1]; const API = "https://api.baselinker.com/connector.php"; (async () => { const params = JSON.parse(fs.readFileSync(process.argv[2], "utf8")); const body = new URLSearchParams({ method: "addInventoryProduct", parameters: JSON.stringify(params) }); console.log("body bytes:", Buffer.byteLength(body.toString())); const r = await fetch(API, { method: "POST", headers: { "X-BLToken": TOKEN, "Content-Type": "application/x-www-form-urlencoded" }, body }); console.log(JSON.stringify(await r.json(), null, 1).slice(0, 1200)); })();