25

How to obtain Wikidata ID from English Wikipedia article name, also for redirects? Is there API call?

Example:

Karachi >> Q8660
Karaachi >> Q8660

How to approach changes in assignment? Now Media in Karachi is redirect to Media of Pakistan (Wikidata item Q6805922), but can be own article later.

3 Answers 3

29

Use Wikipedia API to create a query with property pageprops and resolving redirects:

https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&titles=ARTICLE_NAME

In your case, for Wikipedia articles "Media in Karachi" and "Media of Pakistan" you will get the same Wikidata item ID: Q6805922. Same thing for "Karaachi" and "Karachi"Q8660.

5
4

As well as the accepted answer you can also use the Wikidata API directly passing in a site and a title.

The docs are at https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities

Get the entity for http://en.wikipedia.org/wiki/Karachi:

3
  • do you have an example of an issue solved by the normalize parameter?
    – maxlath
    Mar 26, 2017 at 21:43
  • 1
    Yes, a simple case would be titles=karachi will not return a result as the title is meant to be capitalized, normalize=1 will fix this. I will update the answer.
    – Addshore
    Dec 14, 2017 at 16:20
  • If you mean "en" for English Wikipedia, all you need to do is change the "enwiki" part to some other wiki language, for example "dewiki" for German Wikipedia
    – Addshore
    Oct 26, 2020 at 10:58
3

I needed to do it in Google Sheets, and was able to do it with a formula like this. It assumes the Wikipedia title is in column B. Copy down to the rows you need

=IMPORTXML(concat("https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&format=xml&titles=",B1),"//@wikibase_item")

Another suggestion is to use the dump https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-page_props.sql.gz, 230Mb zipped

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.