In this tutorial, you will learn how to connect the Wikipedia REST API to Google Sheets in 5 steps:
Apipheny is an API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to unlimited API data sources, make unlimited API requests, and more. There is a 30 day free trial included.
1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install
2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.
In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.
Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new
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 command prompt window for Windows OS or a terminal for Mac OS and then press the Enter key:
curl -G "https://en.wikipedia.org/w/api.php?action=query&meta=tokens&format=json&type=login"
Note: For Mac OS you may need to use single quotes ( ‘ ) instead of double quotes ( ” ).
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
Note: If the token/key that you generate has an expiration time, you will need to complete this same process again to get a new token when the old one expires.
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:
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
Don’t forget to replace language_code with a real 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:
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
Don’t forget to replace search_term wit a real value.
If you want to use this same example URL, just copy and paste it into Apipheny.
Headers aren’t required for this 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:
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.
Crypto API Tutorials: