Get link recommendations for revision

POST /service/linkrecommendation/v1/linkrecommendations/wikipedia/{language}/{title}

Given a specific page source, get a set of possible links that can be added to improve an article on Wikipedia.

Examples

curl

# Get link recommendations for a page on English Wikipedia
$ curl -X POST https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/ADD_PAGE_TITLE \
-H "Content-Type: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
--data '{"pageid": 5555, "revid": 5555, "wikitext": "ADD_WIKITEXT_SOURCE"}'

Python

# Python 3
# Get link recommendations for a page on English Wikipedia

import requests
import json

url = 'https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/ADD_PAGE_TITLE'
request_data = {
    'pageid': 5555,
    'revid': 5555,
    'wikitext': 'ADD_WIKITEXT_SOURCE'
}

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
    'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}

response = requests.post( url, headers=headers, data=json.dumps(request_data) )
output = response.json()
print(output)

PHP

<?php
// Get link recommendations for a page on English Wikipedia

$url = 'https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/ADD_PAGE_TITLE';
$fields = [
    'pageid' => 5555,
    'revid' => 5555,
    'wikitext' => 'ADD_WIKITEXT_SOURCE'
];
$json = json_encode( $fields );

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

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' , $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>

JavaScript

// Get link recommendations for a page on English Wikipedia

let url = 'https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/ADD_PAGE_TITLE';
let response = await fetch( url,
    {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
            'Api-User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
        },
        body: JSON.stringify({
            'pageid': 5555,
            'revid': 5555,
            'wikitext': 'ADD_WIKITEXT_SOURCE'
        })
    }
);
response.json()
    .then(console.log).catch(console.error);

Parameters

language

required path

Language code: ar (Arabic), bn (Bangla), cs (Czech), es (Spanish), de (German), el (Greek), en (English), fa (Farsi), fr (French), hu (Hungarian), pl (Polish), pt (Portuguese), ro (Romanian), ru (Russian), simple (Simple English), or vi (Vietnamese)
title

required path

Wiki page title
max_recommendations

optional query

Maximum number of recommendations to return. Default value is 15.
threshold

optional query

Number between 0 and 1 for the threshold to use. Default value is 0.5.

Request schema

pageid

required integer

Page identifier
revid

required integer

Revision identifier
wikitext

required string

Page source in MediaWiki-flavored markup

Headers

Content-Type

required

Specify application/json as the content type.
Authorization

required

Include an access token using the Bearer authentication scheme. For more information about obtaining an access token, visit Authentication.

Responses

200 Success: Page found. Returns a link set object.
Example
{
  "links": [
    {
      "context_after": " to distin",
      "context_before": "cially in ",
      "link_index": 0,
      "link_target": "Science fiction",
      "link_text": "science fiction",
      "match_index": 0,
      "score": 0.5104129910469055,
      "wikitext_offset": 13852
    }
  ],
  "links_count": 1,
  "page_title": "Earth",
  "pageid": 9228,
  "revid": 1013965654
}