A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

Prop=images parameter is not working properly in wikipedia API call

Nikhilesh

I am using the Search API query (“https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=apple&prop=images”) to search for the information based on our search term but the image is not included or returned in the response.

Ciencia-Al-Poder

If you want to get properties of pages retrieved with another module, you need to use generators. In this case, use search as a generator for prop=images. Otherwise, prop=images needs the titles= parameter.

An example:

Nikhilesh

According to you, I have use the search as a generator and also got some images in response but I lost the description in the response. I want descriptions as well as images in response.

(“https://en.wikipedia.org/w/api.php?action=query&format=json&prop=pageimages&generator=search&gsrsearch=apple&piprop=original”)

TheDJ

Unfortunately, that is not possible. Our search results don’t have images (only for File results, where the image is the same as the name of the page being returned).
I don’t think a generator is the best approach here. You might as well make two separate requests and combine the results. You can just pipe all the page ids from your search results into the page images request like this (only 2 page ids in the example):

Tgr

setGeneratorData in ApiPageSet can be used to pass data from generators to the result. Overusing that is discouraged but the search API seems like a sensible candidate for using it. Someone should file a bug <hides>