Skip to main content

Knowledge Base API

Overview

The Knowledge Base API (GKB) provides endpoints for retrieving real-world information about tags and entities, such as details, infoboxes, redirects, and standard forms.

Endpoints

EndpointDescription
Request200 Response
POST /v2/knowledgebase/detailsRetrieves detailed information about tags and entities.
GkbItemsInfoRequestMap[string, Details]
POST /v2/knowledgebase/infoboxesRetrieves information about tags and entities optimized for UI display.
GkbItemsInfoRequestMap[string, LangValueInfoBox]
POST /v2/knowledgebase/redirectsReturns replacements for deprecated knowledge base entities.
GkbItemsRedirectsRequestList[Redirects]
POST /v2/knowledgebase/searchSearches the knowledge base for entities.
GkbItemsSearchRequestList[SearchResults]
POST /v2/knowledgebase/stdformsRetrieves standard forms of tags and entities for a given language.
GkbItemsStdFormRequestMap[string, LangValueString]

POST /v2/knowledgebase/details

Retrieves detailed information about tags and entities.

Example

KB Details

Request

const kbDetails = async (input, config) => {
const response = await axios.post('knowledgebase/details', input, config)
return response.data;
};

input = {
ids: ['Q42'],
language: 'en',
externalSource: 'wikidata'
};

kbDetails(input, config).then(report);

Response

{
Q42: {
gkbId: "G42",
stdForm: {
value: "Douglas Adams",
language: "en"
},
description: {
value: "English science fiction writer and humorist (1952–2001)",
language: "en"
},
type: "person",
subtypes: [],
externalIds: {
wikidata: "Q42"
},
externalLinks: {
"enwiki": "https://en.wikipedia.org/wiki/Douglas_Adams",
"wikidata": "https://www.wikidata.org/entity/Q42"
}
}
}

POST /v2/knowledgebase/infoboxes

Retrieves information about tags and entities optimized for UI display.

Example

KB Infoboxes

Request

const kbInfoBoxes = async (input, config) => {
const response = await axios.post('knowledgebase/infoboxes', input, config)
return response.data;
};

input = {
ids: ['G458', 'G567'],
language: 'fr'
};

kbInfoBoxes(input, config).then(report);

Response

{
G458: {
value: {
title: "Union européenne",
header: "union politico-économique sui generis d'États européens",
body: "",
footer: {
cswiki: "https://cs.wikipedia.org/wiki/Evropská_unie",
enwiki: "https://en.wikipedia.org/wiki/European_Union",
wikidata: "https://www.wikidata.org/entity/Q458",
},
},
language: "fr",
},
G567: {
value: {
title: "Angela Merkel",
header: "chancelière fédérale allemande",
body: "",
footer: {
cswiki: "https://cs.wikipedia.org/wiki/Angela_Merkelová",
enwiki: "https://en.wikipedia.org/wiki/Angela_Merkel",
facebook: "https://www.facebook.com/AngelaMerkel",
instagram: "https://www.instagram.com/bundeskanzlerin",
wikidata: "https://www.wikidata.org/entity/Q567",
},
},
language: "fr",
},
}

POST /v2/knowledgebase/redirects

Returns replacements for deprecated knowledge base entities.

Example

KB Redirects

Request

const itemRedirects = async (ids, config) => {
const response = await axios.post('/knowledgebase/redirects', {gkbIds: ids}, config)
return response.data;
};

ids = ['G1', 'G22262439', 'G8ad70d13-E', 'Gfd6d708c-C'];

itemRedirects(ids, config).then(report);

Response

{
G1: {status: 'active'},
G22262439: {status: 'active', replaces: ['G8ad70d13-E', 'Gfd6d708c-C']},
G8ad70d13-E: {status: 'inactive', replacedBy: 'G22262439'},
Gfd6d708c-C: {status: 'inactive', replacedBy: 'G22262439'}
}

POST /v2/knowledgebase/search

Searches the knowledge base for entities.

Example

KB Search

Request

const itemSearch = async (query, lang) => {
const response = await axios.post('knowledgebase/search', {query: query, language: lang}, config)
return response.data;
};

Response

itemSearch('Jordan', 'en').then(report);

{
query: 'Jordan',
hits: 1,
itemDetails: [
{
gkbId: 'G810',
stdForm: {value: 'Jordan', language: 'en'},
description: {value: 'constitutional monarchy in Western Asia', language: 'en'},
type: 'location'
}
]
}

POST /v2/knowledgebase/stdforms

Retrieves standard forms of tags and entities for a given language.

Example

KB Standard Forms

Request

const kbStdForms = async (input, config) => {
const response = await axios.post('knowledgebase/stdforms', input, config)
return response.data;
};

input = {
ids: ['G458', 'G567'],
language: 'pl',
};

kbStdForms(input, config).then(report);

Response

{
G458: { value: 'Unia Europejska', language: 'pl' },
G567: { value: 'Angela Merkel', language: 'pl' }
}