Feeding Shopify with a Google Merchant Feed

Thomas Weber
4 min readOct 27, 2021
Photo by Jutta Kamp on Unsplash

Google Merchant Center is a digital platform where online retailers can upload product data to feed Google Shopping Ads. For that the retailer has to provide the product information in a format that meets Google’s feed requirements. Given the importance of Google this format is becoming now a defacto standard for exchanging product information.

So some Shopify shop owners are not only interested in posting their products via the Google feed they are also interested in using the feed to setup products within the Shopify store.

Based on some requests in this direction we show here how this can be achieved with Python in a Jupyter Notebook. The example below is a proof of concept it is not a production ready version.

Access a Shopfiy store via the Shopify APIs

Before you can access your Shopify store via the APIs you need to allow “private apps” in you Shopify admin, see here. In this link it is described how to set the access rights and how to generate an API key and a password for your private app. Here we need the right to read and write products.

You can then use the API key and the password directly in the Jupyter Notebook but we prefer to hide them into a text file in our current directory with the name .env. The file should look similar to the one below

Now we can use the Python package python-dotenv to make them available within a Jupyter Notebook. The API key and the password can then be used to set up the headers for requests into the Shopify APIs.

Get the Google Feed

There is an example file from Google which we are using here for illustration porpuses. To make it as practical as possible we setup a server which serves this file (locally). To get the file we are using the Python libraryrequests.

Shopify uses JSON as format, here we have an xml. There is a nice Python library xmltodict available which does the transformation.

Now it is easy to investigate what is in the file. Not surprising the file contains the XML hierachy as described by Google. The product information we are interested in starts in the third level and can be retrieved as

From the output it can be seen that there are six products in the file. Looking at the keys for the first product there are the following entries:

['g:id', 'g:title', 'g:description', 'g:link', 'g:image_link', 'g:condition', 'g:availability', 'g:price', 'g:shipping', 'g:gtin', 'g:brand', 'g:mpn', 'g:google_product_category', 'g:product_type']

Creating the products in Shopify

There are two Shopify APIs which allow to create products in a Shopify shop, the REST and GraphQL API. Since Shopify is pushing into the GraphQL direction we will use it here.

How to create products in the GraphQL API is described here. There is also an example there. Here we use a mutation with variables.

We then loop over the products coming from the Google Feed, set the variable s as they are provided.

(We commented out the part on the images, because these images are not existing.)

Our variable res is used to collect the returned values from the request. This allows us to see if there were errors. Please recall that in the query we asked for the userErrors.

Now the products are available in Shopify and can be seen in the admin area:

Google Feed Products in Shopify

Summary

The creation of products in Shopify from a Google feed requires just a few lines of code. This is also valid for other languages as JavaScript or C# where libraries comparable to XMLtoDict are available.

We did not use all fields coming from the Google Feed in our example. Some are more difficult to map, e.g. ’g:condition’. In real life there are much more fields which need specific attention but the technical aspects are the same as above.

We hope that the example is usefull for you and appreciate any feedback.

--

--