I'm trying to retrieve a list of urls of images in Wikimedia Commons from a particular article. I want to either search article by category and retrieve images from them, or filter images by category. I've tried including incategory:category_name in the titles string of images and article searches as well as [[Category:category%20name]] and Category:category_name to no avail. I'm given the impression it's possible, and the advanced search functionality within Wikipedia would imply so, but how to achieve this through the API is not clear.

Specifically, I'm interested in grabbing these images through the Mediawiki API.

2 Answers 2


Yes, Wikimedia Commons exposes MediaWiki API.

Basically, your query should be the following:

The API:Categorymembers module can be used as a generator.

If you need real URLs of images (not their File: titles), pass results into the API:Imageinfo module:

  • https://commons.wikimedia.org/w/api.php

    "query": {
        "pages": {
          "52082165": {
            "pageid": 52082165,
            "ns": 6,
            "title": "File:\"Flying World\".jpg",
            "imagerepository": "local",
            "imageinfo": [
                "url": "https://upload.wikimedia.org/wikipedia/commons/7/7e/%22Flying_World%22.jpg",
                "descriptionurl": "https://commons.wikimedia.org/wiki/File:%22Flying_World%22.jpg",
                "descriptionshorturl": "https://commons.wikimedia.org/w/index.php?curid=52082165"
          "52082336": {
            "pageid": 52082336,
            "ns": 6,
            "title": "File:\"Before-After the Fall\".jpg",
            "imagerepository": "local",
            "imageinfo": [
                "url": "https://upload.wikimedia.org/wikipedia/commons/2/24/%22Before-After_the_Fall%22.jpg",
                "descriptionurl": "https://commons.wikimedia.org/wiki/File:%22Before-After_the_Fall%22.jpg",
                "descriptionshorturl": "https://commons.wikimedia.org/w/index.php?curid=52082336"

If you need all 1,723 images (which is more than 500), read about generators and continuation.


One API query response has a limit of 500. To ensure your code's resilience and handling of larger categories you need to recursively query the API using continue.cmcontinue if you query using list=categorymembers. Append &origin=* or it could fail due to xhr cross origin.

I wrote a code to go recursive within a large category, and on multiple target categories : https://jsfiddle.net/dekz6Lbu/5/ using JS promises. If you remove GPT's and my comments it's not that long.

See also : https://mediawiki.org/wiki/API:Continue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.