
Idescat exposes some of its data via a collection of REST APIs (RESTful Web Services). Idescat's APIs offer methods for third-party programs to be able to obtain information from the Statistical Institute of Catalonia and integrate it in other services. The use of any of Idescat's APIs requires acceptance of the service terms of use.
| Base URI | http://api.idescat.cat/{service}/v{main version}/{operation}.{format}[?parameters] |
|---|---|
| HTTP Method | GET |
| Response Formats | xml, json, php |
| Version | 1.00 (12.14.2009) |
| Shortcuts | Request, Response |
All requests must specify a service, the main version of the service, a valid operation for the service and a response format. Optionally, a series of general and specific parameters for the service can be specified.
http://api.idescat.cat/{service}/v{main version}/{operation}.{format}[?parameters]
Each service has an identifier, a version and some specific parameters. For example, the Indicators of the day service is identified using the value indicators and has only one version (1).
http://api.idescat.cat/indicadors/v1/{…}
The service identifier determines the root element of the returned document.
The services may have different main versions that are incompatible with each other. Incremental improvements do not affect the main version (for example, 1.01 with respect to 1.00) and therefore do no affect the request either.
The services tend to support a diversity of operations. For example, the service indicators admits the operation data, which returns statistical results, but also the operation nodes.
http://api.idescat.cat/indicadors/v1/dades.{…}
http://api.idescat.cat/indicadors/v1/nodes.{…}
The identifier and the operation determine the structure of the returned document.
It determines the response format. It admits three values:
http://api.idescat.cat/indicadors/v1/dades.xml http://api.idescat.cat/indicadors/v1/dades.php http://api.idescat.cat/indicadors/v1/dades.json http://api.idescat.cat/indicadors/v1/dades.json?callback=f
Every request has some general parameters (common to all services) and some specific parameters of the service, documented in the API of the service.
It admits three values:
http://api.idescat.cat/indicadors/v1/dades.xml?lang=es
This parameter admits two values: utf-8 (default value) and iso-8859-1.
http://api.idescat.cat/indicadors/v1/dades.xml?enc=iso-8859-1
If the response output is php the encoding is UTF-8, whatever the value for enc.
As well as the general parameters described in the previous section, each service admits certain specific parameters ("variables") that can configure the information obtained. These parameters are documented in the service's API.
For example, the operation data of the service indicators can be used to select the number of indicators obtained thanks to the parameters tt, max and min.
http://api.idescat.cat/indicadors/v1/dades.xml?tt=10&max=10&min=3
The service variables (or "specific parameters") can be encapsulated in a general parameter to make a more compact call. To do so, a series of variable/value pairs must be included separated by semicolons.
http://api.idescat.cat/indicadors/v1/dades.json?tt=10&max=10&min=3 http://api.idescat.cat/indicadors/v1/dades.json?p=tt/10;max/10;min/3
Should the server not be able to attend to the request, the code returned will be 500 (Server Error) or 503 (Service Unavailable). In other cases, we can distinguish three types of request that return different HTTP response codes:
In the latter case, the document returned will contain information from the service that has generated it, the error code (within the error element) and the compulsory parameter or parameters for which the value has not been specified (within a missing element for each missing parameter).
http://api.idescat.cat/indicadors/v1/dades.xml?i=
<?xml version="1.0" encoding="utf-8" ?> <indicadors version="1.00" o="dades"> <error>400</error> <missing>i</missing> </indicadors>
At present, the response formats supported are XML, JSON and serialised PHP. For further information, see section 1.1.3 Format.