Hi Magnus,
This lookup is currently done via …
SELECT ips_item_id
FROM wb_items_per_site
WHERE ips_site_id = 'enwiki'
AND ips_site_page = 'Berlin'
This table is on the
wikidata.org repo database.
This lookup may change any time, so better depend on the API whenever you can.
Best
Thiemo