Wikipedia api doesn't return request id

142 views Asked by At

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 :)

2

There are 2 answers

0
Anomie On

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.

1
Leonid On

I have never used MediaWiki API before, but from what I have just done, opensearch does not return requestid. I did https://en.wikipedia.org/w/api.php?requestid=10&action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=jsonfm and it returned


{
    "batchcomplete": "",
    "requestid": "10",
    "query": {
        "pages": {
            "15580374": {
                "pageid": 15580374,
                "ns": 0,
                "title": "Main Page",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "\n{| id=\"mp-topbanner\" style=\"width:100%; background:#f9f9f9; margin:1.2em 0 6px 0; border:1px solid #ddd;\"\n| style=\"width:61%; color:#000;\" |\n\n{| style=\"width:280px; border:none; background:none;\"\n| style=\"width:280px; text-align:center; white-space:nowrap; color:#000;\" |\nWelcome to [[Wikipedia]],\nthe [[free content|free]] [[encyclopedia]] that [[Wikipedia:Introduction|anyone can edit]].\n[[Special:Statistics|{{NUMBEROFARTICLES}}]] articles in [[English language|English]]\n|}\n\n| style=\"width:13%; font-size:95%;\" |\n* [[Portal:Arts|Arts]]\n* [[Portal:Biography|Biography]]\n* [[Portal:Geography|Geography]]\n| style=\"width:13%; font-size:95%;\" |\n* [[Portal:History|History]]\n* [[Portal:Mathematics|Mathematics]]\n* [[Portal:Science|Science]]\n| style=\"width:13%; font-size:95%;\" |\n* [[Portal:Society|Society]]\n* [[Portal:Technology|Technology]]\n* '''[[Portal:Contents/Portals|All portals]]'''\n|}\n\n{{#if:{{Main Page banner}}|\n\n{{Main Page banner}}\n\n\n}}\n\n{| id=\"mp-upper\" style=\"width: 100%; margin:4px 0 0 0; background:none; border-spacing: 0px;\"\n\n| class=\"MainPageBG\" style=\"width:55%; border:1px solid #cef2e0; background:#f5fffa; vertical-align:top; color:#000;\" |\n{| id=\"mp-left\" style=\"width:100%; vertical-align:top; background:#f5fffa;\"\n| style=\"padding:2px;\" | {{#ifexpr:{{formatnum:{{PAGESIZE:Wikipedia:Today's featured article/{{#time:F j, Y}}}}|R}}>150|From today's featured article|Featured article (Check back later for today's.)}}\n|-\n| style=\"color:#000;\" | {{#ifexpr:{{formatnum:{{PAGESIZE:Wikipedia:Today's featured article/{{#time:F j, Y}}}}|R}}>150|{{Wikipedia:Today's featured article/{{#time:F j, Y}}}}|{{Wikipedia:Today's featured article/{{#time:F j, Y|-1 day}}}}}}\n|-\n| style=\"padding:2px;\" | Did you know...\n|-\n| style=\"color:#000; padding:2px 5px 5px;\" | {{Did you know}}\n|}\n| style=\"border:1px solid transparent;\" |\n\n| class=\"MainPageBG\" style=\"width:45%; border:1px solid #cedff2; background:#f5faff; vertical-align:top;\"|\n{| id=\"mp-right\" style=\"width:100%; vertical-align:top; background:#f5faff;\"\n| style=\"padding:2px;\" | In the news\n|-\n| style=\"color:#000; padding:2px 5px;\" | {{In the news}}\n|-\n| style=\"padding:2px;\" | On this day...\n|-\n| style=\"color:#000; padding:2px 5px 5px;\" | {{Wikipedia:Selected anniversaries/{{#time:F j}}}}\n|}\n|}\n{{#switch:{{CURRENTDAYNAME}}|Monday|Friday=\n\n\n\n\n\nFrom today's featured list\n\n{{#ifexist:Wikipedia:Today's featured list/{{#time:F j, Y}}|{{Wikipedia:Today's featured list/{{#time:F j, Y}}}}|{{TFLempty}}}}\n\n\n\n\n|}}\n\n{| id=\"mp-lower\" style=\"margin:4px 0 0 0; width:100%; background:none; border-spacing: 0px;\"\n| class=\"MainPageBG\" style=\"width:100%; border:1px solid #ddcef2; background:#faf5ff; vertical-align:top; color:#000;\" |\n{| id=\"mp-bottom\" style=\"width:100%; vertical-align:top; background:#faf5ff; color:#000;\"\n| style=\"padding:2px;\" | {{#ifexist:Template:POTD protected/{{#time:Y-m-d}}|Today's featured picture | Featured picture (Check back later for today's.)}}\n|-\n| style=\"color:#000; padding:2px;\" | {{#ifexist:Template:POTD protected/{{#time:Y-m-d}}|{{POTD protected/{{#time:Y-m-d}}}}|{{POTD protected/{{#time:Y-m-d|-1 day}}}}}}\n|}\n|}\n\n\n== Other areas of Wikipedia ==\n{{Other areas of Wikipedia}}\n\n== Wikipedia's sister projects ==\n{{Wikipedia's sister projects}}\n\n== Wikipedia languages ==\n{{Wikipedia languages}}\n\n\n{{Main Page interwikis}}{{noexternallanglinks}}{{#if:{{Wikipedia:Main_Page/Tomorrow}}||}}__NOTOC____NOEDITSECTION__"
                    }
                ]
            }
        }
    }
}

As you can see, that has a requestid. I think that MediaWiki does not support using requestid on all actions.

From what I have experimented with, this is expected behaviour.