Getting started with Wikimedia APIs

Wikipedia and other Wikimedia projects are free, collaborative repositories of knowledge, written and maintained by volunteers from around the world. The Wikimedia API gives you open access to add this free knowledge to your projects and apps. In this quick start, you’ll log in, create client credentials, and make your first request.

1. Log in with your Wikimedia account

To log in to the API Portal, use the same account you use for Wikipedia and other Wikimedia projects. If you’re new to Wikimedia (Welcome!), you can create a free account now.

Log in Create account

2. Create a personal API token

Once you’ve logged in, visit API keys to create and manage your API credentials. Select Create key, and select the Personal API token option. This token is tied to your account. It should only be used by you and should not be published or shared. Remember to store your token in a secure place, like a password manager.

API keys

3. Get today’s featured article

For your first request, call the featured content endpoint to get today’s featured article from English Wikipedia. Use your API token to authenticate the request.

curl

# Get today’s featured article from English Wikipedia
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \
"https://api.wikimedia.org/feed/v1/wikipedia/en/featured/$(date +%Y/%m/%d)"

Python

# Python 3
# Get today's featured article from English Wikipedia

import datetime
import requests

today = datetime.datetime.now()
date = today.strftime('%Y/%m/%d')

url = 'https://api.wikimedia.org/feed/v1/wikipedia/en/featured/' + date

headers = {
  'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
  'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}

response = requests.get(url, headers=headers)
data = response.json()
print(data)

PHP

<?php
// Get today's featured article from English Wikipedia

$url = 'https://api.wikimedia.org/feed/v1/wikipedia/en/featured/' . date( 'Y/m/d' );

$token = 'YOUR_ACCESS_TOKEN';
$authorization = 'Authorization: Bearer ' . $token;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' );
$output = curl_exec( $ch );
curl_close( $ch );

echo( $output );
?>

JavaScript

// Get today's featured article from English Wikipedia

let today = new Date();
let year = today.getFullYear();
let month = String(today.getMonth() + 1).padStart(2,'0');
let day = String(today.getDate()).padStart(2,'0');
let url = `https://api.wikimedia.org/feed/v1/wikipedia/en/featured/${year}/${month}/${day}`;

let response = await fetch( url,
    {
        headers: {
            'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
            'Api-User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
        }
    }
);
response.json()
    .then(console.log).catch(console.error);

Learn more Troubleshooting guide

Next steps

Build an app

The Wikimedia API uses OAuth 2.0 for authentication and authorization.

Discover documentation

The API Portal includes all the documentation you need to build free knowledge apps and tools.

  • Check out code samples to get inspired and learn about interacting with wiki pages.
  • Visit the API catalog to discover APIs and stay up to date with the latest changes.

Connect with the community

Join the Wikimedia community, and contribute to free knowledge.