Search API Connector Documentation

Print

Import WooCommerce Data to Google Sheets

In this guide, we’ll walk through how to pull data from the WooCommerce API directly into Google Sheets, using the API Connector add-on for Sheets.

We’ll first get an API key from WooCommerce, and then set up a request to pull in WooCommerce order data to your spreadsheet.

Contents

Before You Begin

Click here to install the API Connector add-on from the Google Marketplace.

Part 1: Get Your WooCommerce API Key

  1. While logged into your WordPress account, click WooCommerce > Settings from the sidebar menu.
    woocommerce-img1
  2. Click the Advanced tab, and then the REST API sub tab. Finally, click either the Add key or the Create an API key button.
    woocommerce-img2
  3. You’ll be presented with a screen to create your API key. Enter in a brief description and click Generate API key
    woocommerce-img3
  4. You will now see your consumer key and consumer secret. Congrats, you can now access the WooCommerce API.
    woocommerce-apikey

Part 2: Fetch Data from WooCommerce

The easiest way to get started with the WooCommerce API is through API Connector’s built-in integration.

  1. Select WooCommerce from the drop-down list of applications
    woocommerce-application
  2. Choose an endpoint.
    woocommerce-endpoints
  3. Enter the required parameters: domain, consumer_key, and consumer_secret
  4. Optionally set any optional parameters such as dates, limits, or product filters
  5. Select a destination sheet, name your request, and click Run.
    woocommerce-response
  6. By default, WooCommerce returns a lot of fields, so filter out any you don’t need using API Connector’s field editor.

Part 3: Create a Custom API Request

Alternatively, you can run your own custom requests instead of using API Connector’s pre-built integration. When you create a custom request, you add your complete URL into the request URL field:

Part 4: Handle Pagination

  1. WooCommerce limits the number of records returned in each request. By default, only 10 records will be returned unless you use the page and per_page parameters as shown below.
    woocommerce-pagination
  2. With API Connector you can loop through these pages automatically with pagination handling (paid feature). WooCommerce provides next page URLs in a Link header (documented here), so set the per_page parameter to 100 and cycle through each page like this:
    • Pagination type: next page URL
    • Field name: Link
    • Run until: choose when to stop fetching data
      pagination-nextpageurl-Link

Part 5: API Documentation

Official API documentation: https://woocommerce.github.io/woocommerce-rest-api-docs/#introduction

Previous Import Wikipedia Data to Google Sheets
Next Import WordPress Data to Google Sheets

22 thoughts on “Import WooCommerce Data to Google Sheets”

    • Sure, based on WooCommerce’s API documentation you can limit orders by date using the ‘before’ and ‘after’ parameters. So, for example, your API request would be something like https://YOUR_DOMAIN.com/wp-json/wc/v3/orders?after=2021-02-21. You can reference cells in your sheet and tie them to a function like =today()-1 to make that date value automatically update each day. Please try that and let me know how it goes!

      Reply
  1. Hey there.

    I am busy running the woocommerce api to fetch my products and the stock level but I am not able to bring in the Variable products.

    Here is my url https://website.co.za/wp-json/wc/v3/products?per_page=50&page=1&status=publish

    I am filtering using JSME
    [].{sku:sku,stock_quantity:stock_quantity,regular_price:regular_price,sale_price:sale_price}

    How would I incorporate that the variants SKU and Stock level also get’s pulled?

    Thanks in advanced if anyone can help.

    Reply
    • Hey Andrew, I can’t really say with this information. Something like [].{sku:sku,stock_quantity:stock_quantity,regular_price:regular_price,sale_price:sale_price,variations:variations} could partially work but I don’t know if stock quantity is available from the /products endpoint, or if ‘variations’ is the field you’re looking for. You basically need to a) confirm that variants SKU and stock level are available metrics returned by the /products endpoint, and then b) check the underlying JSON to contruct a JMESPath query that targets them. If you send me your sample JSON and let me know which fields you want to extract from it I can help you create that JMESPath.

      Reply
  2. Hello,
    First I would like to say that the solution is great and helps a lot. Now I would like to ask a question, how to pull 2 order status at the same time? I tried but only present error. I want to pull orders completed and in processing

    https://website.com/wp-json/wc/v3/orders?per_page=100&status=completed

    and
    &status=processing

    how to do that?

    Thanks!

    Reply
  3. Anyone getting an SSL error when trying to connect into a Woocommerce sandbox account? I can access live accounts without issue.

    Reply
  4. Hey the Link parameter for pagination is not working anymore
    It gives error

    Cannot find function domain in object false

    I think woo has retired this parameter? Is there an alternative?

    Reply
  5. Hello, I followed the instructions above but I’m getting the following error:

    {“code”:”woocommerce_rest_cannot_view”,”message”:”Sorry, you cannot list resources.”,”data”:{“status”:401}}

    Do you know what I’m doing wrong?

    Reply
    • I see a lot of people discussing this problem online, for example here. One of the proposed solutions there is to use Basic authentication instead of passing the key and secret in the URL, like this:

      1. Remove the consumer key and secret parameters from your URL
      2. Encode consumer_key:consumer_secret (you can use the form on this page)
      3. Add a Header of key = Authorization, value = Basic your_encoded_value

      Can you please see if this works for you?
      If not, a different proposed solution was to add a slash before the parameters, like https://example.com/wp-json/wc/v3/products/?
      instead of https://example.com/wp-json/wc/v3/products?

      Reply
    • There’s no realtime sync option but you can update products using a PUT request, and get products with a GET request, and run those on a schedule.

      Reply

Leave a Reply to Dinesh Cancel reply

Table of Contents