← back to Gmc Titlefix
step-b-test-one.js
20 lines
// GATED WRITE — pushes ONE title override. Usage: node step-b-test-one.js <dataSourceName>
const {token,MERCHANT}=require('./_auth');
const fs=require('fs');
const DS=process.argv[2]; // e.g. accounts/146735262/dataSources/1234567890
if(!DS){ console.error('Usage: node step-b-test-one.js <dataSourceName from step A>'); process.exit(1); }
const list=require('./gmc_titlefix_list.json');
const row=list[0]; // first risky offer as the canary
(async()=>{
const tok=await token();
const url=`https://merchantapi.googleapis.com/products/v1/accounts/${MERCHANT}/productInputs:insert?dataSource=${encodeURIComponent(DS)}`;
const body={ offerId:row.offerId, contentLanguage:'en', feedLabel:'US',
productAttributes:{ title: row.proposedTitle } };
console.log('TEST offer:',row.offerId);
console.log(' current :',row.currentTitle);
console.log(' proposed:',row.proposedTitle);
const r=await fetch(url,{method:'POST',headers:{Authorization:'Bearer '+tok,'Content-Type':'application/json'},body:JSON.stringify(body)});
console.log('HTTP',r.status); console.log(JSON.stringify(await r.json(),null,2));
fs.writeFileSync('/tmp/gmc-titlefix-canary-offer.txt', row.offerId);
})();