Notes on Wikipedia / Artsy APIs
I wanted to take some notes on Wikipedia / Artsy AIs that I may use in the future.
I want to go over some APIs that I may want to use for projects in the future.
References
Wikipedia API
The MediaWiki Action API is a web service that allows access to some wiki features like authentication, page operations, and search. It can provide meta information about the wiki and the logged-in user.
Example uses:
- Monitor a MediaWiki installation
- Create a bot to maintain MediaWiki installation
- Log in to a wiki, access data, and post changes by making HTTP requests to the web service
Examples of Wikimedia Wiki Endpoints
API Endpoint | Wiki |
---|---|
https://www.mediawiki.org/w/api.php | MediaWiki API |
https://meta.wikimedia.org/w/api.php | Meta-Wiki API |
https://en.wikipedia.org/w/api.php | English Wikipedia API |
https://commons.wikimedia.org/w/api.php | Wikimedia Commons API |
https://test.wikipedia.org/w/api.php | Test Wiki API |
API Etiquette and Usage Guidelines
There is no hard speed limit on read requests, but be considerate and try not to take a site down. Most system administrators reserve the right to unceremoniously block you if you do endanger the stability of their site. Making your requests in series rather than in parallel, by waiting for one request to finish before sending a new request, should result in a safe request rate. You can include multiple items in one request by:
- Using the pipe character (|) whenever possible, e.g. titles=PageA|PageB|PageC, instead of making a new request for each title
- Using a generator instead of making a request for each result from another request
- Using GZip compression when making API calls by setting Accept-Encoding: gzip to reduce bandwidth usage.
Requests that make edits are subject to rate limiting. When you hit the request rate limit you will receive a API error response with the error code ratelimited. It is best practice to set a descriptive User Agent header. If you are using the API from the browser, you should set the Api-User-Agent header. All new API users should use JSON.
Frequently Asked Questions
What can the MediaWiki Action API be used for?
The MediaWiki Action API can be used to:
- access wiki features
- interact with a wiki
- obtain meta-information about wikis and public users
How to use the API
HTTP requests are usually used to call the Action API. You can try out the API in this sandbox.
What is a module, a submodule, and a parameter?
The MediaWiki Action API has numerous modules that we use to perform different tasks. In technical terms, a module is a subclass of ApiBase. A module requires paramaters. These parameters may (or may not be) submodules.
In this request: https://www.mediawiki.org/w/api.php?action=query&list=search&srsearch=abc&format=json
- action is a parameter of the main module
- action=query is another module. It is called the query module.
- list is a parameter of the query module.
- list=search is also a module. It can be called a submodule of action=query.
- srcsearch is a parameter of the search module. it holds the search string 'abc'.
- format is a parameter of the main module.
- json is the output format.
How do I know which module and submodule to call?
The self-documenting API pages contain a list of all modules and submodules with brief descriptions. You can start at the main module and follow the links to different submodules.
Do I need an access token?
You will require an access token to perform data modifying actions like logging in, editing, moving, page, etc.
Input and Output Formats
The API takes its input through parameters provided by the HTTP request in application/x-www-form-urlencoded or multipart/form-data format. Every module and submodule has its own set of parameters, which are listed in the documentation and in action=help. All encoding should be valid UTF-8. Parameters that take multiple values are normally submitted with the values separated using the pipe character |. If a value contains the pipe character itself, use U+001F as the separator and prefix the value with U+001F, e.g. param=%1Fvalue1%1Fvalue2. If a boolean parameter is specified in an HTTP request, it is considered true regardless of its value. For a false value, omit the parameter entirely. Parameters that take timestamp values accept the timestamp in UNIX timestamp format. The standard and default output format in MediaWiki is JSON.
Errors and Warnings
If something goes wrong in an API request, an error or a warning will be thrown although the HTTP response will usually still be 200 OK. Warnings are thrown for non-fatal conditions such as invalid parameters, whereas errors are only thrown for fatal conditions.
Artsy API
- Create an artsy account
- Sign in to the developer website
- Use your app.
- Create an app and get a Client ID and Client Secret.
- Get a Token:
bash $ curl -v -X POST "https://api.artsy.net/api/tokens/xapp_token?client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET"
```javascript var request = require('superagent');
var clientID = '49d6d75ce4b97878154f', clientSecret = '169814560f096e4b39654dfdd6160189', apiUrl = 'https://api.artsy.net/api/tokens/xapp_token', xappToken;
request .post(apiUrl) .send({ client_id: clientID, client_secret: clientSecret }) .end(function(res) { xappToken = res.body.token; }); ```
- Make Requests.
The base URL of the API is https://api.artsy.net/api. All response bodies are in the JSON+HAL Hypermedia format. Timestamps are in the IDO 8601 format. Links are always contained directly within a resource under the "_links" key. Artsy API s currently rate-limited to 5 requests per second per client application ID. Many content fields in the Artsy API, such as artist bios and gene descriptions, will return data in markdown format. You can use the Artsy API to get information about artists, artworks, collections, and get images.
<aside>
Element
<details>
Element
Comments
You have to be logged in to add a comment
User Comments