[updated answer: using the SPARQL endpoint]
wdq is being replaced by an official SPARQL endpoint, where this query looks like this:
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?item ?itemLabel WHERE {
?item wdt:P646 "/m/0gnfq" .
}
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:
http://wdq.wmflabs.org/api?q=string[646:/m/0gnfq]
Here, I query the wikidata entities with Property 646
of value /m/0gnfq
.
The answer will look like this:
{
"status": {
"error": "OK",
"items": 1,
"querytime": "161ms",
"parsed_query": "STRING[646:'/m/0gnfq']"
},
"items": [
180736
]
}
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 the claim
parameter. An example from the documentation:
claim[138:676555] returns all items that are named after
(P138) Francis of Assisi (Q676555).