Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Metar API

Metar API

The 'Raw' METAR format is one of the most common weather formats used globally for the transmission of observational weather data. The reports are issued with a predictable schedule or when meteorological conditions vacate defined parameters, and since the METAR format is standardised through the International Civil Aviation Organization (ICAO), the language and data presented within the report is easily understood and translated by flight and/or operational aircrew in most parts of the world.

In this article we'll show basic results that might be returned using our own METAR API - the results of which were shown a while back by way of some basic graphs (albeit via an earlier version of the API). While we archive meteorological data from numerous sources that permit feature-rich animations and other graphics, the METAR report is rather bland and boring in comparison. However, if you're in the field of aviation safety investigation (as we are), or you're required to analyse historical airport trends, it'll come in quite useful.

Want access to this API? Like us on Facebook and it'll be made available to you.

The API can be used to return weather information in a number of ways, and only a small portion of data is presented for this cursory introduction. Requests that return formatted data for Google and other charting services, graphs, and so on, are all excluded for the sake of brevity.

The Result

Requests should be made to https://api.beliefmedia.com/platform/sources/metar/metar.json. A number of parameters determines what information is returned.

Browsing Metars

Unless a station (or station="xxxx") is part of your request URL, the results will return YSSY (Sydney). Additionally, if the type is omitted we'll browse results by default. A request to metar.json?apikey=xxxxx&type=browse unfolds as follows.

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [source] => BeliefMedia | NOAA
7
    [api_version] => 0.2
8
    [page] => 1
9
    [number] => 30
10
    [pages] => 461
11
    [total] => 13807
12
    [search] => Array
13
        (
14
            [type] => browse
15
        )
16
 
17
    [results] => Array
18
        (
19
            [0] => Array
20
                (
21
                    [id] => vl0qn
22
                    [station] => YSSY
23
                    [date] => Array
24
                        (
25
                            [mysql] => 2018-04-06 14:30:00
26
                            [time] => 6th April 2018 02:30Z
27
                        )
28
 
29
                    [metar] => Array
30
                        (
31
                            [metar] => YSSY 061430Z 12008KT 9999 FEW016 BKN030 22/19 Q1019 NOSIG
32
                            [temperature] => 22
33
                            [dewpoint] => 19
34
                            [pressure] => 1019
35
                        )
36
 
37
                )
38
 
39
            [1] => Array
40
                (
41
                    [id] => NLwD8
42
                    [station] => YSSY
43
                    [date] => Array
44
                        (
45
                            [mysql] => 2018-04-06 13:30:00
46
                            [time] => 6th April 2018 01:30Z
47
                        )
48
 
49
                    [metar] => Array
50
                        (
51
                            [metar] => YSSY 061330Z 13010KT 9999 FEW015 SCT025 22/20 Q1019 NOSIG
52
                            [temperature] => 22
53
                            [dewpoint] => 20
54
                            [pressure] => 1019
55
                        )
56
 
57
                )
58
 
59
            [.. SNIP ..]
60
 
61
            [29] => Array
62
                (
63
                    [id] => ZYQQR
64
                    [station] => YSSY
65
                    [date] => Array
66
                        (
67
                            [mysql] => 2018-04-05 18:30:00
68
                            [time] => 5th April 2018 06:30Z
69
                        )
70
 
71
                    [metar] => Array
72
                        (
73
                            [metar] => YSSY 051830Z 20011KT 9000 BKN008 21/20 Q1015
74
                            [temperature] => 21
75
                            [dewpoint] => 20
76
                            [pressure] => 1015
77
                        )
78
 
79
                )
80
 
81
        )
82
 
83
)

Pagination can be altered with pg (the page number) and number (the number of results). In all example provided on this page, the order may be altered with order=desc or order=asc.

Current Date and Full Day Reports

To return reports for today only, or reports issued on the current UTC date, use metar.json?apikey=xxxxx&type=today. Results are not paginated and they're returned in a manner identical to the browsing results. To return reports for the last 24 hours (useful when building trending graphs), use metar.json?apikey=xxxxx&type=day. If no station is provided, Sydney (YSSY) results are returned by default. Results are not paginated.

Searching Metars

METARs may be searched via a date range and/or by METAR text. To search via a date range, a start date and/or end date should be provided. The start and end times may be provided in a 6-figure date format (eg: 20180405), a UNIX timestamp, or a date/time string formatted exactly as follows: 23-december-2018-1035. A request made to metar.json?apikey=xxx&type=search&start=20180404&end=6-april-2018-0100&search=nosig returns (in part) the following:

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [source] => BeliefMedia | NOAA
7
    [api_version] => 0.2
8
    [page] => 1
9
    [number] => 30
10
    [pages] => 2
11
    [total] => 55
12
    [search] => Array
13
        (
14
            [type] => search
15
            [term] => nosig
16
            [params] => Array
17
                (
18
                    [start] => 2018-04-04
19
                    [end] => 1522976400
20
                    [station] => YSSY
21
                )
22
 
23
        )
24
 
25
    [results] => Array
26
        (
27
            [0] => Array
28
                (
29
                    [id] => gZ4g6
30
                    [date] => Array
31
                        (
32
                            [mysql] => 2018-04-05 21:30:00
33
                            [time] => 5th April 2018 09:30Z
34
                        )
35
 
36
                    [station] => YSSY
37
                    [metar] => Array
38
                        (
39
                            [metar] => YSSY 052130Z 18011KT 9999 FEW010 22/19 Q1017 NOSIG
40
                            [temperature] => 22
41
                            [dewpoint] => 19
42
                            [pressure] => 1017
43
                        )
44
 
45
                )
46
 
47
            [1] => Array
48
                (
49
                    [id] => zvj38
50
                    [date] => Array
51
 
52
            [.. SNIP ..]

The value of searching free text comes from returning results that might show a particular weather type, or those that contain INTER periods, etc. Results are paginated.

METAR Data

For each report we provide a result that translates portions of the data into a 'human readable' format... or at least a format that's more easily used in other applications. Parsing METAR data can often be problematic because of the human editing that often takes place, the variances that might apply from country to country, and simply the order or manner in which the report is rendered. That said, we chop the report up into pieces and return it as basic data whenever the information complies with an ICAO format. For example, to return a result for KJFK (New York) we'll use metar.json?apikey=xxx&id=z1ZY. The result:

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [source] => BeliefMedia | NOAA
7
    [api_version] => 0.2
8
    [data] => Array
9
        (
10
            [id] => z1ZY
11
            [station] => KJFK
12
            [date] => Array
13
                (
14
                    [mysql] => 2016-12-28 04:00:02
15
                    [time] => 28th December 2016 04:00Z
16
                )
17
 
18
            [metar] => KJFK 271651Z 25010KT 8SM SCT013 BKN036 BKN095 BKN320 14/11 A2982 RMK AO2 RAB1559E08 SLP097 APRNT FROPA VCSH S P0000 T01440111
19
            [data] => Array
20
                (
21
                    [metar] => KJFK 271651Z 25010KT 8SM SCT013 BKN036 BKN095 BKN320 14/11 A2982 RMK AO2 RAB1559E08 SLP097 APRNT FROPA VCSH S P0000 T01440111
22
                    [validity] => Array
23
                        (
24
                            [validity] => 271651Z
25
                            [date] => 27
26
                            [time] => 1651
27
                        )
28
 
29
                    [cloud] => Array
30
                        (
31
                            [SCT013] => Scattered 1300ft
32
                            [BKN036] => Broken 3600ft
33
                            [BKN095] => Broken 9500ft
34
                            [BKN320] => Broken 32000ft
35
                        )
36
 
37
                    [temperature] => Array
38
                        (
39
                            [temperature] => 14
40
                            [dewpoint] => 11
41
                            [hourly] => Array
42
                                (
43
                                    [hourly] => T01440111
44
                                    [temperature] =>  14.4
45
                                    [dewpoint] =>  11.1
46
                                )
47
 
48
                            [relative_humidity] => 82.3
49
                        )
50
 
51
                    [pressure] => Array
52
                        (
53
                            [altimeter] => 1010
54
                            [slp] => SLP097
55
                        )
56
 
57
                    [visibility] => Array
58
                        (
59
                            [0] =>  8SM
60
                        )
61
 
62
                    [wind] => Array
63
                        (
64
                            [wind] => 25010KT
65
                            [direction] => 250
66
                            [strength] => 10KT
67
                            [ordinal_16] => WSW
68
                            [ordinal_32] => WSW
69
                        )
70
 
71
                    [weather] => Array
72
                        (
73
                            [weather] => Array
74
                                (
75
                                    [VCSH] => Showers in the vicinity
76
                                )
77
 
78
                            [rainfall] => Array
79
                                (
80
                                    [rainfall] => RAB1559E08
81
                                    [start] => 1559
82
                                    [stop] => 08
83
                                )
84
 
85
                            [hourly_precipitation] => Array
86
                                (
87
                                    [hourly_precipitation_raw] => P0000
88
                                    [hourly_precipitation] => 0000
89
                                )
90
 
91
                        )
92
 
93
                    [remark] => RMK AO2 RAB1559E08 SLP097 APRNT FROPA VCSH S P0000 T01440111
94
                    [info] => Array
95
                        (
96
                            [AO2] => Automated Observation with precipitation discrimination
97
                        )
98
 
99
                )
100
 
101
        )
102
 
103
)

If the wind is varying we'll return that data in the wind array. Where there's a FM, INTER, or TEMPO period in the forecast, that data is also returned. In fact, just about every METAR variable is returned (there's too many variations to provide examples). An example METAR that shows the data discussed is as follows (metar.json?apikey=xxxxx&id=mZ8A):

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [source] => BeliefMedia | NOAA
7
    [api_version] => 0.2
8
    [data] => Array
9
        (
10
            [id] => mZ8A
11
            [station] => NZWN
12
            [date] => Array
13
                (
14
                    [mysql] => 2016-09-07 17:00:03
15
                    [time] => 7th September 2016 05:00Z
16
                )
17
 
18
            [metar] => NZWN 070630Z AUTO 28008G20KT 230V330 9999 NCD 12/02 Q1002 TEMPO FM0700 30020G35KT
19
            [data] => Array
20
                (
21
                    [metar] => NZWN 070630Z AUTO 28008G20KT 230V330 9999 NCD 12/02 Q1002 TEMPO FM0700 30020G35KT
22
                    [validity] => Array
23
                        (
24
                            [validity] => 070630Z
25
                            [date] => 07
26
                            [time] => 0630
27
                        )
28
 
29
                    [cloud] => Array
30
                        (
31
                            [NCD] => Nil Cloud Detected. 0ft
32
                        )
33
 
34
                    [temperature] => Array
35
                        (
36
                            [temperature] => 12
37
                            [dewpoint] => 02
38
                            [relative_humidity] => 50.7
39
                        )
40
 
41
                    [pressure] => Array
42
                        (
43
                            [altimeter] => 1002
44
                        )
45
 
46
                    [visibility] => Array
47
                        (
48
                            [0] => 9999
49
                        )
50
 
51
                    [wind] => Array
52
                        (
53
                            [wind] => 28008G20KT 230V330
54
                            [direction] => 280
55
                            [strength] => 8KT
56
                            [gust] => 20KT
57
                            [ordinal_16] => W
58
                            [ordinal_32] => WbN
59
                            [varying_from] => 230
60
                            [varying_to] => 330
61
                            [varying_cardinals] => SW to NNW
62
                        )
63
 
64
                    [weather] => Array
65
                        (
66
                            [change] => Array
67
                                (
68
                                    [1] => FM 0700 30020G35KT
69
                                )
70
 
71
                        )
72
 
73
                    [info] => Array
74
                        (
75
                            [AUTO] => Without human editing
76
                        )
77
 
78
                )
79
 
80
        )
81
 
82
)

Note that we don't break down the changes (INTER, TEMPO, FM etc) into smaller chunks. To do so, add complete=yes to your request URL. The primary purpose of returning the results as above was to extract data for wind, dewpoint, humidity, temperature, wind, and other common weather information... so we generally didn't worry too much about returning information that would rarely be used.

PHP Functions

A super-simple function to return search and browsing data is shown below. In reality, you'll want to create an array of options and just merge them with defaults (a long list of arguments isn't a very clever option). We've written the function for illustrative purposes only.

1
<?php 
2
/*
3
 BeliefMedia Metar API
4
 https://www.beliefmedia.com.au/metar-api
5
*/
6
 
7
function beliefmedia_metars($page = '', $number = '', $station = '', $type = false, $search = false, $start = '', $end = '', $order = 'desc', $apikey = 'xxxxx') {
8
 
9
  if ($page == '') $page = '1';
10
  if ($number == '') $number = '20';
11
  if ($type === false) $type = 'browse';
12
  if ($station == '') $station = 'YSSY';
13
 
14
  /* Correct for invalid search type */
15
  $permitted_types = array('browse', 'search', 'today', 'day', 'search');
16
  if (!in_array($type, $permitted_types)) $type = 'browse';
17
 
18
   switch ($type) {
19
       case 'browse':
20
           $query = 'type=browse&pg=' . $page . '&number=' . $number . '&order=' . $order;
21
           break;
22
       case 'today':
23
           $query = 'type=today&order=' . $order;
24
           break;
25
       case 'day':
26
           $query = 'type=day&order=' . $order;
27
           break;
28
       case 'search':
29
           $query = 'type=search&search=' . str_replace(' ', '+', $search) . '&order=' . $order;
30
           if ($start != '') $query .= '&start=' . $start;
31
           if ($end != '') $query .= '&end=' . $end;
32
           break;
33
   }
34
 
35
  $data = @file_get_contents('https://api.beliefmedia.com/platform/sources/metar/metar.json?apikey=' . $apikey . '&station=' . $station . '&' . $query);
36
  if ($data === false) return false;
37
 
38
  $data = json_decode($data, true);
39
  if ($data === false) return false;
40
 
41
  /* Likely return array of errors with code & message */
42
  if ($data['code'] != '200') return $data['message'];
43
 
44
 return (array) $data;
45
}

To return a single report, a function as follows will suffice.

1
<?php 
2
/*
3
 BeliefMedia Metar API
4
 https://www.beliefmedia.com.au/metar-api
5
*/
6
 
7
function beliefmedia_metar($id, $apikey = 'xxxxx') {
8
 
9
  if ($id == '' || $apikey == '') return false;
10
 
11
  $data = @file_get_contents('https://api.beliefmedia.com/platform/sources/metar/metar.json?id=' . $id . '&apikey=' . $apikey);
12
  if ($data === false) return false;
13
 
14
  $data = json_decode($data, true);
15
  if ($data === false) return false;
16
 
17
  /* Likely return array of errors with code & message */
18
  if ($data['code'] != '200') return $data['message'];
19
 
20
 return (array) $data;
21
}

Considerations

  • We've provided snippets of code in the past (including a WordPress plugin) that would return various types of aviation weather reports - including METARS.
  • Our Social Media & Marketing Platform has supported the generation of 'reports to Twitter' for some time, although it's been one of the less utilised features for obvious reasons. While we migrate many of the features of our platform over to the API-centric system, we've disabled adding new airport stations.
  • We archive data dating back to around 2000. However, we regularly archive data leaving around 2 years of reports searchable. To enable a full search, use full=yes in the request URL.
  • Each report is sent to Twitter to its own dedicated account. We've only just started recording the tweet ID, and this is now returned in the JSON response when available.
  • We record weather data from numerous sources... most of it without a mass-market. If you're interested, please make contact with us.
  • To request data from an earlier version of the API, use version=0.2 (where 0.2 is the version you're requesting). To avoid compatibility issues, it's good practice to include the version in all requests.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Connecticut)

  Want to have a chat?
 

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment