API Opendata Documentation
About the AMB’s Opendata portal
This portal hosts a public dataset about the AMB which can be used with the API.
This page shows how to use the open data API to search for and retrieve data from the sources available on the AMB’s portal.
Organisation of information
The Opendata portal lists the information clustered by collections. Each collection can be searched by its fields or by using the free text search option. Query results can be displayed in several formats to make them easier to use. A collection’s data can be accessed using the URL:
http://opendata.amb.cat/{{collection}}/search
where {{collection}} is the collection’s name. Once accessed, it shows all the data available for the collection. Data is currently available for these collections:
-
http://opendata.amb.cat/activitats/search
-
http://opendata.amb.cat/noticies/search
-
http://opendata.amb.cat/municipis/search
-
http://opendata.amb.cat/publicacions/search
-
http://opendata.amb.cat/estudis/search
-
http://opendata.amb.cat/estudis/search/?tipus_estudi=Mobilitat
-
http://opendata.amb.cat/estudis/search?rows=15&tipus_estudi=metropolitans
-
http://opendata.amb.cat/estudis/search?rows=15&tipus_estudi=sostenibilitat
-
http://opendata.amb.cat/projectes_obres/search
-
http://opendata.amb.cat/infraestructures/search
-
http://opendata.amb.cat/tramits/search
-
http://opendata.amb.cat/cooperacio/search
-
http://opendata.amb.cat/equipaments/search
-
http://opendata.amb.cat/equipaments_platja/search
-
http://opendata.amb.cat/equipaments/search?subambit=Parcs
-
http://opendata.amb.cat/pla_urbanistic/search
-
http://opendata.amb.cat/datasets/search
-
Contractor profile - open procedures:
http://opendata.amb.cat/perfil_contractant_procediment_obert/search
-
Contractor profile - negotiated procedures::
http://opendata.amb.cat/perfil_contractant_procediment_negociat/search
-
http://opendata.amb.cat/activitats_taxi/search
-
http://opendata.amb.cat/noticies_taxi/search
-
http://opendata.amb.cat/notes_premsa/search
-
http://opendata.amb.cat/dades_meteorologiques/search
-
http://opendata.amb.cat/dades_estat_platja/search
-
Prat de Llobregat beach facilities
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_prat
-
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_montgat
-
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_gava
-
Castelldefels beach facilities
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_castelldefels
-
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_barcelona
-
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_badalona
-
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_viladecans
-
Sant Adrià de Besòs beach facilities
http://opendata.amb.cat/serveis_platges/search?platja_key=platja_sadria
-
http://opendata.amb.cat/serveis_empreses/search
-
http://opendata.amb.cat/prestador_serveis/search
-
http://opendata.amb.cat/workshops_pdu/search
-
http://opendata.amb.cat/vehicles_taxi/search
-
http://opendata.amb.cat/directori_taxi/search
-
http://opendata.amb.cat/parades_taxi/search
-
http://opendata.amb.cat/punts_interes/search
-
http://opendata.amb.cat/serveis_parcs/search
-
http://opendata.amb.cat/ocupacio_publica/search
-
http://opendata.amb.cat/projectes_oberts/search
-
http://opendata.amb.cat/publicacions_taxi/search
-
http://opendata.amb.cat/punts_serveis/search
-
http://opendata.amb.cat/serveis_platges/search
-
http://opendata.amb.cat/workshops_oberts/search
-
http://opendata.amb.cat/workshops_passatges/search
-
http://opendata.amb.cat/contactes/search
-
http://opendata.amb.cat/menu_site/search
Each collection is associated with a schema which defines the types of fields and the organisation of its contents. The schema of a collection can be viewed using the URL:
http://opendata.amb.cat/{{collection}}/schema
For example, if you look up the news schema you get this information:
Collection searches
Field specific searches
The API allows you to search by a collection’s fields. The searches are made as follows:
http://opendata.amb.cat/{{collection}}/search?{{camp1}}={{valor}}&{{camp2}}={{valor}}&{{camp3}}={{valor}}
where camp1, camp2, camp3 are the names of the fields in the collection. For example, if you want to filter the results by the news title field,you would make the following query:
http://opendata.amb.cat/noticies/search?titol=metropolitans
f the field you need to filter is a nested field (i.e., inside another node), the field name will be the concatenation of all its parent nodes with a "." and the field name. For example, if you need to search for the enllacos_relacionats_nom field you would make the following search:
http://opendata.amb.cat/noticies/search?enllacos_relacionats.enllacos_relacionats_nom=premsa&titol=metropolitans
Free text searches
You can also conduct free text searches by the text fields in each collection. You do this by using the q field in the URL. For example, the following query will search for the word mobility in the collection fields:
http://opendata.amb.cat/noticies/search?q=mobilitat
You can combine this type of search with a field-specific search. An example would be the following:
http://opendata.amb.cat/noticies/search?enllacos_relacionats.enllacos_relacionats_nom=premsa&titol=metropolitans&q=mobilitat
Date field searches
You can make Date field searches using the nomenclature dd/mm/yyyy. An example would be the following search:
http://opendata.amb.cat/noticies/search?enllacos_relacionats.enllacos_relacionats_nom=premsa&titol=metropolitans&q=mobilitat&data_noticia=25/09/2014
You can also search by date range using the symbols <,>,= inside the field value. For example, if you need to retrieve news where the date must be after 25/09/2014, you would make the following call:
http://opendata.amb.cat/noticies/search?enllacos_relacionats.enllacos_relacionats_nom=premsa&titol=metropolitans&q=mobilitat&data_noticia=>25/09/2014
Pagination
The API returns the results grouped in 500 items by default in all your searches. If you look at the header of the results of a search you can identify the elements:
num: number of elements shown in the search.
count: total number of elements in the search.
start: first element of the list shown.
To enable pagination in the API, you have to specify the number of elements you want to retrieve (rows) and which element you want to retrieve the results from (start):
http://opendata.amb.cat/parades_taxi/search?rows=500&start=1000
Sorting
The API allows you to sort the results by a particular field in ascending or descending order. In the search, you need to specify which field you want to sort by and the direction: sort={{camp}},{{asc/desc}}.
http://opendata.amb.cat/noticies/search?titol=metropolitans&sort=autor,asc
Return specific fields in the response
The API allows you to filter the fields returned in the response items. This means you can significantly reduce the search information. For example, if you only need the entry and author fields, you can do this by using the getFields parameter:
http://opendata.amb.cat/noticies/search?q=mobilitat&getFields=entradeta,autor
This feature is only valid for first level fields, i.e., ones that come directly from the item’s root.
Search by different values in the same field
You can search for a field where its value matches one of those specified in the search field. To do this you have to separate each value by the symbol |:
http://opendata.amb.cat/activitats/search?subambit=Residus|Sostenibilitat|Aigua
The example will search for all contents in which the subfield matches any of the query’s values.
Bear in mind that the parameter’s values need to be exactly the same as the values you are searching for (i.e., capital letters, accents, punctuation marks, etc. must match).
Data formats
The API serves the results in JSON format by default. You can also get search information in XML, KML, KMZ and CSV formats. The searches are made as follows:
http://opendata.amb.cat/{{collection}}/search/{{format}}?{{camp1}}={{valor}}&{{camp2}}={{valor}}&{{camp3}}={{valor}}
where the {{format}} field is the type of format you need. A search by XML format would be as follows
http://opendata.amb.cat/noticies/xml/search?enllacos_relacionats.enllacos_relacionats_nom=premsa&titol=metropolitans&q=mobilitat
Other search utilities
Get related fields
Some collections contain contents related to the contents of other collections. For example, the activities collection has contents related to facilities and publications. To see this relationship, you need to add the parameter getRelatedArticles=true to your query:
http://opendata.amb.cat/activitats/search?tema=residus&getRelatedArticles=true
With the previous search, you get the related contents of each item. The following code shows how the related_articles field appears, indicating that a given content is related to two contents of publicacions and eight contents of equipaments_platja.
If you want to see related content, you should search in the relevant collection by the articleId field.