I'm trying to make several Ajax requests to Wikipedia. The Ajax calls are in a for-loop (JavaScript), which is a problem because they return out of order. In order to work around this I thought I'd include a request ID to the Ajax request as is an option in their sand box. Problem is that the ID doesn't return...?
(From Wikimedia's sandbox)
https://en.wikipedia.org/wiki/Special%3aApiSandbox#action=opensearch&format=json&requestid=12&search=clownfish
returns:
[
"clownfish",
[
"Clownfish",
"Clown"
],
[
"To the scientific name of an organism: This is a redirect from a vernacular (\"common\") name to the scientific name of an organism (or group of organisms).",
"Clowns are comic performers who employ slapstick or similar types of physical comedy, often in a mime style."
],
[
"https://en.wikipedia.org/wiki/Clownfish",
"https://en.wikipedia.org/wiki/Clown"
]
]
No requestid. But when I change the action from "opensearch" to something else, it does return a request id.
https://en.wikipedia.org/wiki/Special%3aApiSandbox#action=cspreport&format=json&requestid=12
returns:
{
"error": {
"code": "cspreport-wrongformat",
"info": "Error processing CSP report: wrongformat.",
"*": "See https://en.wikipedia.org/w/api.php for API usage."
},
"requestid": "12",
"servedby": "mw1194"
}
As you can see, this response does include a requestid.
Is this expected behavior, or am I missing something? Any help is much appreciated :)
The OpenSearch Suggestions extension specification does not allow for additional return values such as the requestid. This is also why the opensearch module has a parameter to treat warnings as errors, since it can't return warnings either.
Try using action=query&list=prefixsearch instead. That gives the same results as action=opensearch but in the MediaWiki action API's standard format.