AEMET OpenData API does not return body

1

I am trying to use the Aemet API to add weather forecast to one of my apps, but all calls return an empty body.

As I see in the documentation, this call should return the data of the last 24 hours, but it returns a 200 without body:

link

Documentation: link

Also, I would like to know where to find the {idema} codes for all the cities, since they do not appear in that documentation. For example for the request link {idema} which is the same as the previous one but for a single city.

Greetings and thanks!

    
asked by Javier Delgado 19.04.2017 в 12:11
source

1 answer

3

You need to provide a valid ApiKey, otherwise it will return a correct answer (Status 200) but no content in the body.

You can get the ApiKey valid for 90 days in a simple way here .

Regarding the ids of the automatic meteorological stations (idema), I do not know if there is a list of all the existing ones at the national level, the Junta de Andalucía, for example, if it provides a list of those located in the community on its website.

What you can do is get the list by parsing the JSON of the /opendata/api/observacion/convencional/todas response.

I do not know what language you use for the app but testing in Python 3.6 you get the answer without problems:

import http.client
import ssl
import json

apyKey='eyJhbGciOiJIUzI1NiJ9...' #<<< Sustituir por ApiKey válida 

context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
conn = http.client.HTTPSConnection("opendata.aemet.es", context = context)



headers = {
    'cache-control': "no-cache"
    }

conn.request("GET", f"/opendata/api/observacion/convencional/todas?api_key={apyKey}", headers=headers, )
res = conn.getresponse()
data = res.read().decode('utf-8','ignore')
data = json.loads(data)

conn.request("GET", data['datos'], headers=headers, )
res= conn.getresponse()
datos = res.read().decode('utf-8','ignore')
datos= json.loads(datos)

idemas = {estacion['ubi']:estacion['idema'] for estacion in datos}

print(idemas['GRANADA/AEROPUERTO'])

idemas is a dictionary that contains the location and idema of all stations returned by the query:

  

VANDELLS: 0002I
  ALFORJA: 0009X
  REUS / AIRPORT: 0016A
  VALLS: 0034X
  TARRAGONA FAC. GEOGRAPHY: 0042Y
  PONTONS: 0061X
  VILAFRANCA DEL PENEDS: 0066X
  SITGES-VALLCARCA: 0073X
  BARCELONA / AIRPORT: 0076
  BERGA INSTITUTE: 0092X
  BALSARENY: 0106X
  PRATS DE LLUANS: 0114X
  MOI: 0120X
  MANRESA: 0149X
  MONTSERRAT: 0158X
  IGUALADA: 0171X
  CORBERA PIC D? AGULLES: 0194D
  BARCELONA CMT: 0201D
  ...

I leave you a link to a Blog with information on the use of the api OpenData of the AEMET in case you find it helpful.

    
answered by 19.04.2017 / 16:32
source