Search code examples
mediawikiwikipediawikipedia-apimediawiki-api

Wikipedia Mediawiki API get URL in query


Using the MediaWiki API I have a query that returns the results I want:

https://en.wikipedia.org/w/api.php?action=query&list=allpages&apfrom=Apple&aplimit=5

How can I modify it to also include the URL for each of the pages that are returned?

I tried adding the "info" property and "url" info, but it does not return additional information:

https://en.wikipedia.org/w/api.php?action=query&list=allpages&apfrom=Apple&aplimit=5&prop=info&inprop=url

Solution

  • You need to move the parameters you use to get the result to a generator instead of a list and then use prop=info and inprop=url in the query. Like this:

    https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info&generator=allpages&inprop=url&gapfrom=Apple&gaplimit=5