A simple library to generate Google Merchant XML Feed
npm install google-merchant-feed
import { FeedBuilder } from "google-merchant-feed";
const feedBuilder = new FeedBuilder();
feedBuilder.withTitle("Test Store");
feedBuilder.withLink("https://example.com");
feedBuilder.withDescription("An example item from the feed");
feedBuilder.withProduct({
id: "DB_1",
title: "Dog Bowl In Blue",
description: "Solid plastic Dog Bowl in marine blue color",
link: "http://www.example.com/bowls/db-1.html",
imageLink: "http://images.example.com/DB_1.png",
availability: "in_stock",
price: {
currency: "GBP",
value: 9.99,
},
shipping: {
country: "UK",
service: "Standard",
price: {
currency: "GBP",
value: 4.95,
},
},
googleProductCategory: "Animals > Pet Supplies",
customLabels: ["Made in Waterford, IE"],
// Other fields
});
// More products
feedBuilder.withProduct({
// ...
});
const xml = feedBuilder.buildXml();
console.log(xml);
XML generated by the code above:
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>Test Store</title>
<link>https://example.com</link>
<description>An example item from the feed</description>
<item>
<g:id>DB_1</g:id>
<g:title>Dog Bowl In Blue</g:title>
<g:description>Solid plastic Dog Bowl in marine blue color</g:description>
<g:link>http://www.example.com/bowls/db-1.html</g:link>
<g:image_link>http://images.example.com/DB_1.png</g:image_link>
<g:availability>in_stock</g:availability>
<g:price>9.99 GBP</g:price>
<g:google_product_category>Animals > Pet Supplies</g:google_product_category>
<g:custom_label_0>Made in Waterford, IE</g:custom_label_0>
<g:shipping>
<g:country>UK</g:country>
<g:service>Standard</g:service>
<g:price>4.95 GBP</g:price>
</g:shipping>
</item>
</channel>
</rss>