I would like to know, is there a way to find a Wikidata entity by specified property using their API. For example, there are plenty entities that have Freebase ID property (Property:P646). It's unique identifier and I want to get an entity by this identifier.
Anyone know how to achieve this?
[updated answer: using the SPARQL endpoint]
wdq is being replaced by an official SPARQL endpoint, where this query looks like this:
you can try it at query.wikidata.org
and to get this query's results in JSON, you can make a request at "https://query.wikidata.org/sparql?format=json&query=YOURQUERY" where YOURQUERY is the URI-encoded SPARQL query:
https://query.wikidata.org/sparql?format=json&query=PREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%20PREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%20SELECT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%20%3Fitem%20wdt%3AP646%20%22%2Fm%2F0gnfq%22%20.%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20.%20%7D%20%7D
[old answer: using WDQ]
you can fetch the wmflabs API (documentation) like this:
Here, I query the wikidata entities with Property
646
of value/m/0gnfq
.The answer will look like this:
The entity I was looking for is thus
Q180736
.Here, the query uses the
string
parameter as freebase IDs are strings in wikidata, but for properties implying wikidata entities as value type, you will need to use theclaim
parameter. An example from the documentation: