3

If I know that Kanye West's Spotify ID is 5K4W6rqBFWDnAN6FQUkS6x, what is the easiest way to resolve that identifier to his Wikidata page, which is https://www.wikidata.org/wiki/Q15935 ?

Do I need to do this with a SPARQL query or is there a way to do this using the MediaWiki JSON API?

Simon Willison
  • 15,642
  • 5
  • 36
  • 44
  • I don't think there is a way to do it using the MediaWiki API (I wouldn't call that easier than using SPARQL, anyway). – Tgr Apr 29 '17 at 08:24

2 Answers2

5

Using SPARQL:

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT * { ?s wdt:P1902 "5K4W6rqBFWDnAN6FQUkS6x" }

Wikidata SPARQL endpoint address is https://query.wikidata.org/sparql.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • 2
    you can [test this query here](https://query.wikidata.org/#SELECT%20%2a%20%7B%20%3Fs%20wdt%3AP1902%20%225K4W6rqBFWDnAN6FQUkS6x%22%20%7D) and get the associated JSON by passing an URI encoded version of the SPARQL to `https://query.wikidata.org/sparql?format=json&query=` [like so](https://query.wikidata.org/sparql?format=json&query=PREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0ASELECT%20*%20%7B%20%3Fs%20wdt%3AP1902%20%225K4W6rqBFWDnAN6FQUkS6x%22%20%7D%0A) – maxlath Apr 28 '17 at 20:17
  • Perfect! Thanks very much, that's exactly what I needed. – Simon Willison May 06 '17 at 16:29
2

You could also use the tool Resolver, that makes just this (but it is not the MediaWiki API). This will just forward you to the Wikidata page. From your example: https://tools.wmflabs.org/wikidata-todo/resolver.php?prop=P1902&value=5K4W6rqBFWDnAN6FQUkS6x

Ainali
  • 1,613
  • 13
  • 23