In this tutorial, you will learn how to connect the Wikipedia REST API to Google Sheets in 5 steps:

  1. Install the Apipheny Add-on
  2. Obtain an API Token (if needed)
  3. Obtain an Endpoint URL
  4. Enter Wikipedia API into Apipheny
  5. Run the Wikipedia API request

Step 1.) Install and open the Apipheny Add-on in Google Sheets

To pull data from the Wikipedia API into Google Sheets, first install and open the Apipheny Google Sheets add-on.

Apipheny is an API integrator for Google Sheets that you can use to make unlimited API requests, connect to unlimited APIs, save API requests, schedule API requests, and more. Click here for more information about Apipheny. There’s a 30-day free trial included, then it’s $19-$29/month.

1. You can install Apipheny by opening the following link on desktop and then clicking the Install button on the next page: https://gsuite.google.com/marketplace/app/apipheny/966163326746

Install Apipheny
Install Apipheny

2. After you’ve installed Apipheny, open a Google Sheet and then click on Add-Ons in the top menu. In the add-ons menu, you should see Apipheny.

Then click Import API to open the Apipheny sidebar in your Google Sheets.

Open Apipheny
Open Apipheny

Step 2.) Obtain an API Token (if needed)

The API:Tokens module provides tokens required by data-modifying actions, such as logging, editing or moving a page, as well as watching or patrolling changes. For each action, you will need a specific type of token.

For example, if you want to login to a wiki site via the Action API, you would need a token of type “login” to proceed.

To obtain a login token, write the following command in your terminal window and then press the Enter key:

curl -G "https://en.wikipedia.org/w/api.php?action=query&meta=tokens&format=json&type=login"
Requesting login token
Requesting login token

The type parameter value depends on the type of token you want to obtain. It could be createaccount, csrf, deleteglobalaccount, login, patrol, rollback, setglobalaccountstatus, userrights or watch. The default value is csrf.

If you want to retrieve two tokens simultaneously, then the type parameter will have the two values separated by the pipe symbol (“|”):

https://en.wikipedia.org/w/api.php?action=query&meta=tokens&format=json&type=login|patrol

Step 3.) Obtain an Endpoint URL

In this section, I’ll show you how to browse the Wikipedia API documentation to find an API URL that retrieves the information you need. If you already know your API URL, or you want to use the same example URL as us, just skip to Step 4.

First, open the Wikipedia API documentation page: https://www.mediawiki.org/wiki/API:Main_page

The menu on the right contains the list of links for the available API endpoints, grouped by their roles:

Wikipedia API endpoints
Wikipedia API endpoints

If you click on an API endpoint, then that endpoint’s page will open, containing its description and documentation.

All API calls to Wikipedia should be made to the http://en.wikipedia.org/w/api.php base domain.

Wikipedia API base domain/root URL:
http://en.wikipedia.org/w/api.php

An example endpoint is Search for a language:

https://en.wikipedia.org/w/api.php?action=languagesearch&format=json&search=<language code>

The documentation for each endpoint contains the HTTP method used (eg. GET), a description of the endpoint’s purpose, a list of its actions, parameters, possible errors and relevant usage examples:

Wikipedia endpoint description page
Wikipedia endpoint description page

Step 4.) Enter the Wikipedia API URL Into Apipheny

Go back to your Google Sheet and make sure that the Apipheny add-on is open with the “Import” tab open.

Then enter these details into the add-on:

Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your API endpoint. For this example, we are using the GET method.

API URL: In Step 3, we explained how you can find the Wikipedia API endpoint that you need. Now copy the complete API URL and endpoint into the Apipheny add-on, where it says API URL Path, followed by any GET parameters required for your query.

For this example, we are using the Search for a title or a text endpoint, to obtain a title or a text in a wiki:

https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=<search term>&utf8=&format=json

If you want to use this same example URL, just copy and paste it into Apipheny.

Headers aren’t required for this API request.

Wikipedia API request in Apipheny
Wikipedia API request in Apipheny

Step 5.) Run the Wikipedia API Request

Your last step is to click the Run button at the bottom of the Apipheny add-on and then wait for the Wikipedia API data to be pulled in to your Google spreadsheet:

Wikipedia API data in Google Sheets
Wikipedia API data in Google Sheets

After making a successful request to the Wikipedia API, try querying a different endpoint, or try using one of the more advanced features in the Apipheny add-on.

Related articles:

Related Posts

Leave a Comment