
The Indicators of the day service provides basic information on a selection of short-term and structural indicators for the Catalan economy.
The use of this service requires acceptance of the Terms of use of Idescat's APIs.
| Base URI | http://api.idescat.cat/indicadors/v1/{operation}.{format}[?parameters] |
|---|---|
| HTTP Method | GET |
| Response Formats | xml, json, php |
| Version | 1.00 (12.14.2009) |
| Shortcuts | Request, Response, Examples |
| Operations | dades, nodes |
| Widgets that use this service | Latest indicators, Graph of the evolution of indicators |
All requests must specify the service, version, operation and format. Version and operation are specific characteristics to each service. If nothing is stated to the contrary, the service supports the general response formats of Idescat's APIs. For more information, please consult the section Anatomy of requests in the general documentation of Idescat's APIs.
The Indicators of the day service is identified using the value indicators.
http://api.idescat.cat/indicadors/v1/{…}
It allows two types of operation:
http://api.idescat.cat/indicadors/v1/dades.{…}
http://api.idescat.cat/indicadors/v1/nodes.{…}
The specific parameters ("variables") make it possible to select the information that will be returned by a certain operation of the Indicators of the day service. They can be specified as individual parameters or in a single parameter p (compact form). In this documentation, the compact form is always used.
To find out the general parameters available for any service, consult the Idescat's APIs documentation.
It permits selection of a fixed set of indicators or the most recent ones (whatever they are).
To find out the identifiers of the different available indicators, use the operation nodes. Example 23 shows the current list of indicators and their identifiers.
If this variable of selection is present (even if it has no assigned value), the rest of the specific parameters are ignored.
http://api.idescat.cat/indicadors/v1/dades.xml?p=i/0801,0802
It permits selection of indicators in accordance with the combination of three criteria:
The indicators are returned in reverse chronological order.
http://api.idescat.cat/indicadors/v1/dades.xml?p=tt/14;max/10;min/3
http://api.idescat.cat/indicadors/v1/dades.json?p=tt/0;max/3;min/3
http://api.idescat.cat/indicadors/v1/dades.php?p=tt/3;max/0;min/0
http://api.idescat.cat/indicadors/v1/dades.xml?p=tt/0;max/0;min/0
Warning: The response time for this request can be slow. It is advisable to size requests to realistic information needs. One should never request all indicators without maintaining some kind of caché in the requesting machine.
It returns a list of available indicators, with their identifier and a description, grouped into sections and subsections. The parameter i can be used to filter the sections being shown.
To find out the identifiers of the currently available sections, use the operation nodes without specifying i.
http://api.idescat.cat/indicadors/v1/nodes.json?callback=func
http://api.idescat.cat/indicadors/v1/nodes.xml?p=i/0
To find out the HTTP response codes returned and the formats supported by any service, consult section 2 of Idescat's APIs.
The root element (indicators) includes the following attributes:
<indicadors xmlns:dc="http://purl.org/dc/elements/1.1/" version="1.00" lang="ca" o="dades" n="6" p="tt=0;max=6;min=6;" >
<indicadors version="1.00" lang="ca" o="nodes" n="84" p="i=0,1" >
The information for each indicator is included in the i element. As well as information for Catalonia, it may include comparative information for one or more geographical regions (at present, only Spain).
<i id="0302"> <c>Pernoct. hotels</c> <r title="gen/09">2009-01</r> <d>Variació interanual de pernoctacions en establiments hotelers</d> <v>-12.0</v> <s>Idescat, a partir de l'Enquesta d'ocupació hotelera de l'INE</s> <vc g="es">-11.5</vc> <sc g="es">INE</sc> <ts>-1.0,7.9,15.2,-16.6,2.4,-1.2,2.8,1.4,-3.7,-5.6,-10.5,-6.6,-12.0</ts> <tsc g="es">1.2,8.6,9.6,-11.9,6.2,-2.8,0.4,-0.5,-3.2,-5.3,-11.0,-10.6,-11.5</tsc> <u s="%">%</u> <l>http://www.idescat.cat/economia/inec?tc=3&id=0302</l> <m>http://www.idescat.cat/economia/inec?tc=7&id=0302</m> <t i="c">Conjuntura econòmica</t> <dc:date>2009-03-04T14:07:00+00:00</dc:date> </i>
The general elements are:
Indicators of the day is designed as a service that provides information for Catalonia. Additionally, it can offer the same information for other areas for comparative purposes. The information for Catalonia is contained in the following elements (which are always present):
The elements that contain values can have decimal points (for example, "10.5"). Missing values are indicated by "_".
If there is information available for other geographic areas, the elements vc, tsc and sc are included, which have the same meaning as the corresponding v, ts and s. These three new elements include an attribute g that indicates the geographic area (at the moment this is always equal to "es"). If the last value of the series of the area of comparison (tsc) is not available, vc will be present but with the value "_".
As at the moment, the source of the data (both for Catalonia and for Spain) is not translated, when requesting the result in a different language to Catalan both s and sc will include a lang attribute equal to "ca".
The indicators are grouped into sections and subsections. This hierarchy is expressed in a series of nested v elements. Each element has an identifier (id attribute). The end nodes (indicators) contain a text that describes the type of computation (desc attribute) and the indicator's update time (date attribute).
<v id="0">Indicadors de conjuntura
<v id="00">Comptabilitat trimestral
<v id="0005"
desc="Variació interanual en volum corregida d'efectes estacionals i de calendari"
date="2009-11-20T14:36:00+00:00">
PIB</v>
</v>
<v id="01">Indústria
<v id="0101"
desc="Variació interanual de l'índex de producció industrial"
date="2009-10-14T08:32:00+00:00">
IPI
</v>
<v id="0102"
desc="Saldo de respostes sobre el clima industrial"
date="2009-11-06T10:53:00+00:00">
Clima industrial
</v>
<v id="0103"
desc="Variació interanual de la facturació d'energia elèctrica"
date="2009-11-10T12:08:00+00:00">
Energia elèctrica
</v>
</v>
...
</v>
Idescat's APIs use standardised response codes to indicate whether the request has been successful or has failed. Requests to the API for Indicators of the day may be successful, but not return any of the requested indicators, maybe because they do not exist at the moment or have never existed (incorrect identifier), or maybe because the indicator is temporarily unavailable (for example, because it is being revised).
The i element of the indicator without information will provide the error attribute to indicate:
It is possible to know the number of indicators for which valid information has been returned thanks to the attribute n of the element indicators.
<?xml version="1.0" encoding="utf-8" ?>
<indicadors
xmlns:dc="http://purl.org/dc/elements/1.1/"
lang="ca"
o="dades"
n="1"
p="i=0501,9999,0701"
>
<i id="0501" error="403">
<c>Vehicles</c>
</i>
<i id="9999" error="404">
<c>Indicador no trobat</c>
</i>
<i id="0701">
<c>IPC</c>
<r title="set/09">2009-09</r>
<d>Variació interanual de l'índex de preus de consum</d>
<v>-0.5</v>
<s>INE</s>
<vc g="es">-1.0</vc>
<sc g="es">INE</sc>
<ts>4.5,3.6,2.5,1.6,1.1,1.0,0.4,0.4,-0.3,-0.5,-0.9,-0.3,-0.5</ts>
<tsc g="es">4.5,3.6,2.4,1.4,0.8,0.7,-0.1,-0.2,-0.9,-1.0,-1.4,-0.8,-1.0</tsc>
<u s="%">%</u>
<l>http://10.116.2.23/economia/inec?tc=3&id=0701</l>
<m>http://10.116.2.23/economia/inec?tc=7&id=0701</m>
<t i="c">Conjuntura econòmica</t>
<dc:date>2009-10-14T08:32:00+00:00</dc:date>
</i>
</indicadors>
The element v of existing indicators but that are temporarily unavailable will have an error attribute with value 403. Also, it will not have attributes desc and date.
<v id="59">Sector exterior <v id="5901" error="403">Exportacions</v> <v id="5905" desc="Variació de les importacions" date="2009-10-24T17:32:00+00:00">Importacions</v> </v>
The following request is for the latest indicator available in JSON format (UTF-8, in English) with callback function:
http://api.idescat.cat/indicadors/v1/dades.json?p=max/1;min/1&callback=f&lang=en
Its result can be processed in Javascript to show the basic information associated to the latest indicator in the following way:
<script type="text/javascript">
<!--//--><![CDATA[//><!--
function f(json) {
var html;
if(document.getElementById){
document.getElementById("darrerindicador").innerHTML="Loading...";
if (json) {
if(typeof(json) == "object" && typeof(json.indicadors) == "object" && json.indicadors.n==1){
html =
"<ul><li><strong>Concept:<\/strong> "+ json.indicadors.i.c + "<\/li>"+
"<li><strong>Reference date:<\/strong> "+ json.indicadors.i.r.title + "<\/li>"+
"<li><strong>Value:<\/strong> " +
json.indicadors.i.v + json.indicadors.i.u.s.content + "<\/li>"+
"<li><strong>Meaning:<\/strong> " + json.indicadors.i.d + "<\/li>" +
"<li><strong>Results:<\/strong> <a href=\""+json.indicadors.i.l.replace(/&/g,"&")+"\">" +
json.indicadors.i.l.replace(/&/g,"&") + "<\/a><\/li>" +
"<li><strong>Methodology:<\/strong> <a href=\""+json.indicadors.i.m.replace(/&/g,"&")+"\">" +
json.indicadors.i.m.replace(/&/g,"&") + "<\/a><\/li>" +
"<li><strong>Date of update:<\/strong> " +
json.indicadors.i['dc:date'].substring(8,10) +"."+
json.indicadors.i['dc:date'].substring(5,7) + "." +
json.indicadors.i['dc:date'].substring(0,4)+ "<\/li>"+
"<\/ul>"
;
}else{
html = "The service didn't return the requested information.";
}
}else{
html = "The service is not available at this moment.";
}
document.getElementById("darrerindicador").innerHTML=html;
}
}
//--><!]]>
</script>
<div id="darrerindicador">Connecting...</div>
<script type="text/javascript"
src="http://api.idescat.cat/indicadors/v1/dades.json?p=min/1;max/1&callback=f&lang=en">
</script>
The following request is for the latest 6 (default value) indicators in XML format:
http://api.idescat.cat/indicadors/v1/dades.xml?lang=en
This result can be transformed using an XSLT document to obtain an HTML fragment that can be inserted in a web page. The following example shows an XSLT document that generates a similar table to that shown on the Idescat homepage on the basis of the information provided by this previous request.
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
indent="yes" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
<xsl:variable name="lang" select="/indicadors/@lang" />
<xsl:template match="/">
<style type="text/css">
#IdescatInd {
margin: 0.5em;
width: 278px;
}
#IdescatInd, #IdescatInd a {
font-size: 11px;
font-family: verdana,arial,helvetica,swiss,sans-serif;
}
caption, tr.cap {
display: none;
}
a:link, a:visited, a:hover, a:active {
text-decoration: none;
color: #00c;
}
a:visited {
font-style: italic;
}
a.neg:link, a.neg:visited, a.neg:hover, a.neg:active {
color: #c00;
}
table {
width: 100%;
border: 0;
border-collapse: collapse;
}
th {
font-weight: normal;
text-align: left;
vertical-align: top;
background-image: none;
padding: 0;
background-color: inherit;
}
tr {
border-bottom: 1px dotted #ccc;
}
td {
text-align: right;
vertical-align: bottom;
padding: 0;
}
th, td {
white-space: nowrap;
border-bottom: 1px dotted #ccc;
padding-bottom: 1px;
}
tr.over td, tr.over th,
tr:hover * {
background-color:#f0f0f0;
}
.over {
cursor: pointer;
}
em {
display: block;
text-align: center;
padding-top: 0.5em;
}
</style>
<script type="text/javascript">
function c(e){
var link=e.getElementsByTagName('a')[0];
window.top.location.href=link.href;
}
function v(e){
e.className='over';
}
function o(e){
e.className='';
}
</script>
<div id="IdescatInd">
<xsl:variable name="sum">
<xsl:choose>
<xsl:when test="$lang='es'">
<xsl:value-of select="'Últimos indicadores publicados'"/>
</xsl:when>
<xsl:when test="$lang='en'">
<xsl:value-of select="'Latest indicators'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Darrers indicadors publicats'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<table summary="{$sum}">
<caption>
<xsl:choose>
<xsl:when test="$lang='es'">Selección de indicadores</xsl:when>
<xsl:when test="$lang='en'">Selection of indicators</xsl:when>
<xsl:otherwise>Selecció d'indicadors</xsl:otherwise>
</xsl:choose>
</caption>
<tbody>
<tr class="cap">
<th scope="col">
<xsl:choose>
<xsl:when test="$lang='en'">Indicator</xsl:when>
<xsl:otherwise>Indicador</xsl:otherwise>
</xsl:choose>
</th>
<th scope="col">
<xsl:choose>
<xsl:when test="$lang='en'">Value</xsl:when>
<xsl:otherwise>Valor</xsl:otherwise>
</xsl:choose>
</th>
</tr>
<xsl:apply-templates select="/indicadors/i"/>
</tbody>
</table>
</div>
</xsl:template>
<xsl:template match="i">
<xsl:variable name="v" select="v"/>
<tr title="{d}" onclick="c(this)" onmouseover="v(this)" onmouseout="o(this)">
<th scope="row" class="over"><a href="{l}"><xsl:value-of select="c"/>
<xsl:text> </xsl:text><xsl:value-of select="r/@title"/></a></th>
<td class="over">
<xsl:choose>
<xsl:when test="$lang='en' or not(contains($v,'.'))"><xsl:value-of select="$v"/></xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($v,'.')"/>,<xsl:value-of select="substring-after($v,'.')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="u='%'"><xsl:value-of select="u"/></xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text><xsl:value-of select="u"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
(To simplify, this XSLT document includes the generation of the CSS and Javascript code in the middle of the HTML code: but this information would normally be specified in separate files as it does not depend on the result of the request.)
Idescat's APIs can be combined with other APIs to create a new service (what is known as a mashup). The following example illustrates this possibility: it uses the Indicators of the day API to obtain updated information on exports (i=0801) and imports (i=0802) for Catalonia and the Google Chart API to graphically represent the data.
In the example, the information is requested in serialised PHP format and is processed with PHP. The page is ISO-8859-1 encoded and uses the indicadors() function which admits a list of identifiers ("0801,0802": exports and imports).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Example of the use of the Indicators of the day API with PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en" />
<style type="text/css">
body {
font-family: Arial, Helvetica, Swiss, sans-serif;
}
a {
display: block;
}
img {
border: none;
}
h1 {
text-align: center;
border-bottom: 1px dotted #ccc;
font-size: 100%;
}
.graf {
float: left;
width: 170px;
margin: 0.4em;
}
</style>
</head>
<body><?php indicadors("0801,0802"); ?></body>
</html>
The indicadors() function obtains data from Idescat and passes it to the graf() function that generates the HTML code for the graph in accordance with the Google Chart API. The unserialize() PHP function is used to convert the information obtained into an object.
function indicadors($id){
$url="http://api.idescat.cat/indicadors/v1/dades.php?i=".$id."&lang=en";
$r = file_get_contents($url);
if ($r === false) {
print("The request has failed.");
return;
}
$o = unserialize($r);
if(is_object($o) && $o->indicadors){
if(is_array($o->indicadors->i)){
foreach ($o->indicadors->i as $indicador){
graf($indicador);
}
}else{
graf($o->indicadors->i);
}
}else{
print("The response is not correct.");
return;
}
}
The graf() function takes the object with the information requested as its argument and processes it to generate the HTML code with the Google Chart graph.
On the understanding that in the example the HTML page is ISO-8859-1 and that the serialised PHP format always returns the codified result as UTF-8, some literals would have to be converted using the PHP utf8_decode() function.
The request could contain an incorrect indicator identifier. Or the indicator may be temporarily unavailable. The graf() function detects these situations when an error attribute appears within element i and generates a message informing of this.
function graf($o){
if(isset($o->error)){
print("<div class=\"graf\">Error ".$o->error.": ".utf8_decode($o->c).": ".$o->id."</div>");
return;
}
$nom = utf8_decode($o->c." ".$o->r->title);
if(strpos($o->ts,"_")===false){
$cos=24;
$pos=55;
$wh="170x100";
$colors=array("text"=>"000000","XAxis"=>"CCCCCC","line"=>"336699","punt"=>"ff0000");
$serie=$o->ts;
$vserie=split(',',$serie.",0");
$max = max($vserie);
$min = min($vserie);
$valor = $o->v;
$unitats = $o->u->content;
if($unitats=="%") $valor.=$unitats;
$url = str_replace("&","&",$o->l);
$desc = utf8_decode($o->d);
$grafic="http://chart.apis.google.com/chart?cht=lc&chs=".$wh."&chd=t:0,0|".$serie."&chds=".$min.",".
$max."&chxt=r,x,y&chxl=0:|".$valor."|1:||2:||&chxs=0,".$colors['text'].",".$cos.
",0,_|1,CC0000,1,0,_|2,CC0000,1,0,_&chco=".$colors['XAxis'].",".$colors['line'].
"&chls=1,1,0|1,1,0&chxp=0,".$pos."&chm=o,".$colors['punt'].",1,12,6,0";
print("<div class=\"graf\"><h1>".$nom."</h1><a href=\"".$url."\"><img src=\"".$grafic."\" alt=\"".$valor."\" title=\"".
$desc."\" /></a></div>");
}else{
print("<div class=\"graf\">".$nom.": There are missing values</div>.");
}
}
<?php
function indicador($id){
$url="http://api.idescat.cat/indicadors/v1/dades.php?i=".$id."&lang=en";
$r = file_get_contents($url);
if ($r === false) {
print("The request has failed.");
return;
}
$o = unserialize($r);
if(is_object($o) && $o->indicadors){
if(is_array($o->indicadors->i)){
foreach ($o->indicadors->i as $indicador){
graf($indicador);
}
}else{
graf($o->indicadors->i);
}
}else{
print("The response is not correct.");
return;
}
}
function graf($o){
if(isset($o->error)){
print("<div class=\"graf\">Error ".$o->error.": ".utf8_decode($o->c).": ".$o->id."</div>");
return;
}
$nom = utf8_decode($o->c." ".$o->r->title);
if(strpos($o->ts,"_")===false){
$cos=24;
$pos=55;
$wh="170x100";
$colors=array("text"=>"000000","XAxis"=>"CCCCCC","line"=>"336699","punt"=>"ff0000");
$serie=$o->ts;
$vserie=split(',',$serie.",0");
$max = max($vserie);
$min = min($vserie);
$valor = $o->v;
$unitats = $o->u->content;
if($unitats=="%") $valor.=$unitats;
$url = str_replace("&","&",$o->l);
$desc = utf8_decode($o->d);
$grafic="http://chart.apis.google.com/chart?cht=lc&chs=".$wh."&chd=t:0,0|".$serie."&chds=".$min.",".
$max."&chxt=r,x,y&chxl=0:|".$valor."|1:||2:||&chxs=0,".$colors['text'].",".$cos.
",0,_|1,CC0000,1,0,_|2,CC0000,1,0,_&chco=".$colors['XAxis'].",".$colors['line'].
"&chls=1,1,0|1,1,0&chxp=0,".$pos."&chm=o,".$colors['punt'].",1,12,6,0";
print("<div class=\"graf\"><h1>".$nom."</h1><a href=\"".$url."\"><img src=\"".$grafic."\" alt=\"".$valor."\" title=\"".
$desc."\" /></a></div>");
}else{
print("<div class=\"graf\">".$nom.": There are missing values</div>.");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Example of the use of the Indicators of the day API with PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en" />
<style type="text/css">
body {
font-family: Arial, Helvetica, Swiss, sans-serif;
}
a {
display: block;
}
img {
border: none;
}
h1 {
text-align: center;
border-bottom: 1px dotted #ccc;
font-size: 100%;
}
.graf {
float: left;
width: 170px;
margin: 0.4em;
}
</style>
</head>
<body>
<?php indicador("0801,0802"); ?>
</body>
</html>
The following example shows how to process the information in the indicators of the day tree.
<?php
$url="http://api.idescat.cat/indicadors/v1/nodes.php?lang=$lang";
function Literal($s){
return utf8_decode(str_replace("&","&",$s));
}
function print_tr($o,$e){
switch($e){
case 0:
print("<table class=\"ApartNum Interactiva\"><caption>".Literal($o->content).
"</caption><tbody><tr class=\"cap\"><th scope=\"col\" class=\"etieti\">Name</th>".
"<th scope=\"col\">Identifier</th></tr>");
break;
case 1:
print("<tr class=\"separada total\"><th colspan=\"2\" scope=\"col\">".Literal($o->content)."</th></tr>\n");
break;
default:
if($o->desc){
$desc=Literal($o->desc);
}else{
$desc="Indicator temporarily unavailable";
}
print("<tr title=\"$desc\"><th scope=\"row\">".Literal($o->content)."</th><td>".Literal($o->id)."</td></tr>\n");
break;
}
}
$r = file_get_contents($url);
if ($r !== true) {
$o = unserialize($r);
if(is_object($o) && $o->indicadors){
foreach($o->indicadors->v as $apart){
print_tr($apart,0);
foreach($apart->v as $subapart){
print_tr($subapart,1);
if(is_array($subapart->v)){
foreach($subapart->v as $indicador){
print_tr($indicador,2);
}
}else{
print_tr($subapart->v,2);
}
}
print("</tbody></table>");
}
}else{
print("<p>Error: The response is not correct.</p>");
}
}else{
print("<p>Error: The request has failed.</p>");
}
?>