Various API URL Examples for Calling Wikipedia Api

In this post, we're going to see some of the Wikimedia API URL formats.

Posted by Author At June 12th, 2016

Wikipedia has large set of options available for calling the api, and retrieving different kind of results just by modifying the url parameters. It’s often confusing since lots of optional parameters can be placed in the api url.

So in this post, I’m going to list some of the important api url formats that have been in most uses.

1. https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=meaning&titles=computer&prop=info&inprop=url&format=jsonfm

This will search the article which includes “computer” keyword in its title and retrieves them. The prop properties retrieves the normal info about the pages and inprop=url, retrieves the original, edit as well as canonical uri related to the page. The result of this call will be multi dimensional object, make sure the parse them correctly.

2. https://en.wikipedia.org/w/api.php?action=opensearch&search=bee&limit=1&format=jsonfm

This uri, has a opensearch as a action parameter, and this returns an multidimensional array of the exact search match, in case of this particular call, since we’re trying to fetch the information about ‘bee’, the exact result retrieves the title, short description as well as the url of the bee page.  

If there is no exact match however similar match, the result retrives , ‘{query} may refers to’ and the url of that related match.

3. https://en.wikipedia.org/w/api.php?format=jsonfm&action=query&prop=extracts&exintro=&explaintext=&titles=hello

This api call, retrieves almost exactly the same result as in the prvious one, but this time the prop=extracts parameters retrieves the extracts from the page.

4. https://en.wikipedia.org/w/api.php?action=parse&section=0&prop=text&page=hello 

 

This call retrieves the html of the page content.

5. https://en.wikipedia.org/w/api.php?action=query&list=search&format=jsonfm&srsearch=hello

This call retrieves the list of search matching the srsearch parameter, in case of this particular call, it returns the basic info of the pages matching the query.

The format should be json, these url use jsonfm, just to give the html representation of the json, so that it would be easy to see what’s it’s retrieving. However when you work on the api, it probably should be json.

There are other hundreds of way to retrieve results, you can find them on the documentation page.


Posted Under