0

i would like to retrieve properties of a wikidata entry (eg I want to retrieve date of birth (P569) of Donald Trump (Q22686)). I tried to use wbgetentities as action but failed to retrieve more than the description of the wikidata entry. Is it possible to retrieve the properties with wbgetentities?

import requests

API_ENDPOINT = "https://www.wikidata.org/w/api.php"
    query = "Q66505"
    params = {
        'action': 'wbgetentities',
        'format': 'json',
        'languages': 'de',
        'ids': query,
        'props': 'labels|descriptions'
    }
    r = requests.get(API_ENDPOINT, params = params)
    print(r.json())

I looked at the description but I could not find the solution: https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities

mango123
  • 29
  • 5

1 Answers1

0

what you're looking for is props=claims: https://www.wikidata.org/w/api.php?action=wbgetentities&props=claims&ids=Q66505&format=json

maxlath
  • 1,804
  • 15
  • 24
  • Great! Thanks a lot. @maxlath, any idea if it is also possible to display the "text" (label?) of a property? E.g., for P21 which represents gender the json file displays: "id": "Q6581072" which is female. For P101 (occupation) it shows Q131524 (which is entrepreneur) and I would love to have the information "female" and "entrepreneur" in the json already without having to query the codes. Maybe this is also a simple add on to the query? – mango123 Jun 15 '21 at 13:39
  • that's not possible in only one API query, afaik, you would need to pass by the SPARQL query service, for instance something like https://w.wiki/3VZ5 – maxlath Jun 16 '21 at 14:41