Skip to content

mw api

Releasev0.35.0 · cfeceb67

Watch it in action

Query a local wiki API
mw api <endpoint-or-url> [flags]

Make a REST request relative to https://wikimedia.org/api/rest_v1/, or supply an absolute HTTP(S) URL. JSON is indented and coloured in a terminal and compact when piped. Other response bodies are printed unchanged. Requests return a failing exit status for HTTP errors. No credentials are added automatically.

Fields are strings: they form a JSON body and select POST by default, or query parameters with –method GET. Use –input FILE (or - for stdin) for a custom body, and –header for authentication or content types.

--base-url <string>
Base URL for relative endpoints Default: https://wikimedia.org/api/rest_v1/.
-f, --field <stringArray>
String field as name=value (repeatable)
--format <string>
Format the specified output
-H, --header <stringArray>
Request header as 'Name: value' (repeatable)
-i, --include
Include the response status and headers
--input <string>
Request body file, or - for stdin
-X, --method <string>
HTTP method (GET, or POST when --field/--input is provided)
-o, --output <string>
Output format (jq|json) Default: json.
--raw
Print the response body unchanged
--timeout <duration>
HTTP request timeout Default: 20s.
--help
Help for this command
--no-interaction
Do not ask any interactive questions
-v, --verbose <count>
Increase output verbosity. Example: --verbose=2 or -vv
Terminal window
mw api 'metrics/pageviews/top/en.wikipedia.org/all-access/2025/01/01'
mw api 'https://en.wikipedia.org/w/rest.php/v1/search/page' -X GET -f q=Earth
mw api 'metrics/pageviews/top/en.wikipedia.org/all-access/2025/01/01' --output jq --format '.items[0].articles[:5]'
mw api 'https://example.org/api/resource' -X POST --input request.json -H 'Content-Type: application/json'
Report an issue with this page

Report a documentation issue

The report includes this page’s link, section and documentation version.

Review and submit on Phabricator, or run the command using your saved CLI profile. The command asks before creating the task.