Commons:API/MediaWiki
Jump to navigation
Jump to search
Examples of using the MediaWiki API on Commons content.
See also the experimental Commons:Commons API
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]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]obtaining 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)