Search API Connector Documentation

Print

Import WordPress Data to Google Sheets

In this guide, we’ll walk through some examples of how to pull data from the WordPress API directly into Google Sheets, using the API Connector add-on for Sheets. In this article we’ll pull in public WordPress data (a future article will show how to pull in private data with the help of an authentication plugin).

Note that this guide refers to WordPress.org, the self-hosted version of WordPress, not WordPress.com.

CONTENTS

BEFORE YOU BEGIN

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

PART 1: CREATE YOUR API REQUEST URL

We’ll first get a list of your public posts.

  • API root: https://mixedanalytics.com (substitute in your own hostname)
  • Endpoint: /wp-json/wp/v2/posts
  • Query strings: per_page=100&context=embed

Putting it together, we get the full API Request URL:

hhttps://mixedanalytics.com/wp-json/wp/v2/posts?per_page=100&context=embed

The query strings are optional but will help you get more records and send back a briefer response (without context=embed, the API will return the full text of each article, which can produce too much data for Sheets to handle).

PART 2: PULL WORDPRESS DATA INTO GOOGLE SHEETS

Now let’s copy and paste that URL into API Connector.

  1. Open up Google Sheets and click Add-ons > API Connector > Open.
  2. In the Create tab, enter the API URL we just created.
    wordpress-img1  
  3. We don’t need any headers so just leave that section blank. We don’t need any extra authentication, either, so leave authentication set to None.
  4. Create a new tab and click ‘Set current’ to use that tab as your data destination.
  5. Name your request and click Run. A moment later you’ll see the latest posts in your sheet.
    wordpress-img2

PART 3: MORE EXAMPLE API URLS

You can experiment with endpoints and query strings as described in the documentation to see other types of WordPress data, but if you just want to jump in and get a feel for it, play around with the URLs you enter in the API URL path field. Try the following (one at a time), substituting in your own site name.

  • categories
    https://your-site.com/wp-json/wp/v2/categories
  • comments
    https://your-site.com/wp-json/wp/v2/comments
  • pages
    https://your-site.com/wp-json/wp/v2/pages

PART 4: HANDLE PAGINATION

The WordPress API limits the number of records returned in each request. By default, only 10 records will be returned unless you paginate through records as described in their documentation. This is why we set the per_page=100 parameter in our first example query above.

To get more than 100 records, you need to paginate through with the page and per_page parameters as shown in their documentation:
wordpress-img3

With API Connector you can either run those request URLs manually or loop through them automatically with pagination handling (paid feature), like this.

  • API URLenter your request URL as usual, including the per_page=100 parameter
  • Pagination typepage parameter
  • Page parameterpage
  • Number of pagesenter the number of pages you’d like to fetch
    wordpress-img4

Leave a Comment