Commons:API/MediaWiki

From Wikimedia Commons, the free media repository
Jump to: navigation, search

Examples of using the MediaWiki API on Commons content.


Categories[edit]

api.php?action=query&titles=Image:Commons-logo.svg&prop=categories
list categories for Image:Commons-logo.svg

Image info[edit]

api.php?action=query&titles=Image:Commons-logo.svg&prop=imageinfo
image info - Image:Commons-logo.svg last file revision uploader name, timestamp

Metadata[edit]

https://commons.wikimedia.org/w/api.php?action=query&titles=Image:Commons-logo.svg&prop=imageinfo&iiprop=metadata&iimetadataversion=latest
Raw metadata that is embedded in file. More information on the format
https://commons.wikimedia.org/w/api.php?action=query&titles=Image:Commons-logo.svg&prop=imageinfo&iiprop=extmetadata
Includes metadata from file page

Templates[edit]

api.php?action=query&titles=Image:Commons-logo.svg&prop=templates
list templates used on Image:Commons-logo.svg

Random file[edit]

api.php?action=query&list=random&rnnamespace=6&rnlimit=1

Get files uploaded by a particular user[edit]

api.php?action=query&list=logevents&letype=upload&leuser=FlickrLickr
list of uploads by User:FlickrLickr. May include duplicates and files that don't exist.
https://commons.wikimedia.org/w/api.php?action=query&list=allimages&aiuser=FlickrLickr&aisort=timestamp
Alternative method for getting uploads by User:FlickrLickr. Will only include files where the most recent version of the file is uploaded by User:FlickrLickr. Will not include files that don't exist.

Get files in a particular category[edit]

api.php?action=query&list=categorymembers&cmtype=file&cmtitle=Category:CC-BY-2.0
Images in Category:CC-BY-2.0

Retrieve files given a pair of coordinates (latitude, longitude)[edit]

optaining thumbnail urls with an API request, using list=geosearch as a generator

action=query&generator=geosearch&ggsprimary=all&ggsnamespace=6&ggsradius=500&ggscoord=51.5|11.95&prop=imageinfo&iiprop=url&iiurlwidth=200
Files next to 51.5 (lat) 11.95 (lon)