I would like to get all images in a category in Wikimedia Commons. Let's say category X, but exclude those which are also in category Y. I do not understand if I can actually do this.
This will get all of them, but how to exclude some?
moreover I would like in the result to have the description of the images, not just the name of the file, is that possible?
AFAIK, there is no way to get that directly using the API. But, assuming both categories are reasonably small, you could get all images from both of them and then compute the complement in your code.
To retrieve the description, you can use
prop=imageinfo&iiprop=extmetadata&iiextmetadatafilter=ImageDescription
.In the context of your example query, it would look like this:
https://commons.wikimedia.org/w/api.php?action=query&generator=categorymembers&gcmtype=file&gcmtitle=Category:X&prop=imageinfo&iiprop=extmetadata&iiextmetadatafilter=ImageDescription