我在我的大型商店上寻找产品xml Feed,格式类似于:https://www.shopperapproved.com/api/product-example.xml
大型商务是否提供产品的xml供稿,例如站点地图,或者这是我必须单独导出和上传的内容?
感谢您的反馈。
答案 0 :(得分:1)
BigCommerce确实提供了xml产品导出,但它不是您想要的格式。
为了以您想要的格式获取产品xml,您需要使用BigCommerce API。
要使用API,您需要在旧版API部分的商店后端创建API用户。
执行此操作后,您将拥有API用户,密钥和API路径。拿这三件事将它们插入下面的python脚本中。
我在这里做了几个假设。
以下将创建一个名为out.xml的xml文件。 将文件另存为products.py并从命令行运行它:
python products.py
该脚本需要Python 2.7.6并且您需要安装请求库
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')