Alexis C
Alexis C

Reputation: 23

Big Commerce Product Xml Feed

I am looking for a product xml feed on my big commerce store, in a format similar to this: https://www.shopperapproved.com/api/product-example.xml

Does big commerce provide an xml feed of products, like the sitemap, or is this something I have to export and upload separately?

Thanks for any feedback.

Upvotes: 1

Views: 1231

Answers (1)

Domenic Schiera
Domenic Schiera

Reputation: 89

BigCommerce does provide an xml export of products, but it is not in the format that you want.

In order to get the products xml in a format that you want, you will need to use the BigCommerce API.

To use the API you need to create an API user in the backend of your store in the Legacy API section.

After you do that you will have an API user, a key, and an API path. Take these three things and plug them into the following python script.

I have made a couple assumptions here.

  1. Manufacturer is the brand from BigCommerce.
  2. MPN is the SKU from BigCommerce

The following will create an xml file called out.xml. Save the file as products.py and run it from the command line:

python products.py

The script requires Python 2.7.6 and that you install the requests library

pip install requests

products.py:

import requests
import xml.etree.ElementTree as ET

api_path = 'https://store-xxxxxx.mybigcommerce.com/api/v2/' #From the Legacy API. This is an example.
user = '<your username>'    #API username that you created.
api_key = '<your api_key>'
products = requests.get(api_path + 'products.json', auth=(user,api_key)

products_xml = ET.Element('products')

for product in products.json():
    product_xml = ET.SubElement(products_xml, 'product')
    product_xml.set('id',str(product['id']))
    name = ET.SubElement(product_xml, 'name')
    name.text = str(product['name'])
    description = ET.SubElement(product_xml, 'description')
    description.text = str(product['description'])
    manufacturer = ET.SubElement(product_xml, 'manufacturer')
    brand = requests.get(api_path + product['brand']['resource'][1:] + '.json', auth=(user,api_key)) # Need to make another call to get the brand.
    if (brand.status_code == 200):
        manufacturer.text = str(brand.json()['name'])   # I'm assuming the manufacturer is the brand
    image = ET.SubElement(product_xml, 'image')
    image.text = str(product['primary_image']['standard_url'])  #other ways to map this as well.
    mpn = ET.SubElement(product_xml, 'mpn')
    mpn.text = str(product['sku'])  # Again, I'm assuming.
tree = ET.ElementTree(products_xml)
tree.write('out.xml')

Upvotes: 1

Related Questions