Send API Call for Historical AIS Messages

You can request any AIS messages with timestamps within the past seven days from the Messages API. This can be done via the received_after and received_before API parameters.

For instance, the following command requests AIS messages with timestamps from 2018-05-25 from 00:00:00 to 00:02:00:

GET https://ais.spire.com/messages?fields=decoded&received_after=2018-05-25T00:00:00&received_before=2018-05-25T00:02:00

Similar to queries for recent AIS messages, API responses above a certain size get paginated with cursors to refer to the next page of results (see API Calls: Getting Started).

Going forward in time, the after and before  parameters point to your following page of results:

{
    "paging": {
        "limit": 20000,
        "after": "MjAxOC0wNS0yNSAwMDowMDoxNiswMDowMA==",
        "actual": "20000+",
        "before": "MjAxOC0wNS0yNSAwMDowMjowMCswMDowMA=="
    },
    "data": [
        {
            "msg_type": 1,
            "msg_id": "1527206400_273824000",
            "course": 304.6,
            "collection_type": "satellite",
            "nmea": "!AIVDM,1,1,,B,1458q0700RC=UC0RuNh;qar00000,0*39",
            "rot": 0,
            "id": "a0eb2135-142c-4009-96e6-3d302d403f09",
            "speed": 3.4,
            "source": "FM61",
            "latitude": 61.0981333333,
            "type": 1,
            "accuracy": 0,
            "status": 7,
            "maneuver": 0,
            "timestamp": "2018-05-25T00:00:00+00:00",
            "mmsi": 273824000,
            "flag": "Russia",
            "created_at": "2018-05-25T07:30:50.144283+00:00",
            "msg_description": "position",
            "longitude": -178.7859733333,
            "flag_short_code": "RU",
            "position": {
                "type": "Point",
                "coordinates": [
                    -178.7859733333,
                    61.0981333333
                ]
            },
            "heading": 317
        },
        {
            "msg_type": 1,
            "msg_id": "1527206400_235335000",
            "course": 66,
            "collection_type": "satellite",
            "nmea": "!AIVDM,1,1,,B,13PKeF0036bafB0I4G82U27n0000,0*03",
            "rot": 0,
            "id": "4b1b6c63-8b9f-4c1d-910b-0fda9e8573c0",
            "speed": 19.8,
            "source": "FM61",
            "latitude": 43.80976,
            "type": 1,
            "accuracy": 1,
            "status": 0,
            "maneuver": 0,
            "timestamp": "2018-05-25T00:00:00+00:00",
            "mmsi": 235335000,
            "flag": "United Kingdom",
            "created_at": "2018-05-25T07:30:50.144283+00:00",
            "msg_description": "position",
            "longitude": 148.9246933333,
            "flag_short_code": "GB",
            "position": {
                "type": "Point",
                "coordinates": [
                    148.9246933333,
                    43.80976
                ]
            },
            "heading": 67
        },


To fetch additional pages of results, include the subsequent  after and before cursors in your following API calls:

GET https://ais.spire.com/messages?fields=decoded&after=MjAxOC0wNS0yNSAwMDowMDoxNiswMDowMA==&before=MjAxOC0wNS0yNSAwMDowMjowMCswMDowMA==

And so forth...

Below is some output from our sample Python Historical Messages API Client as it goes through all of the results:

Start Querying SPIRE Data...
https://ais.spire.com/messages?fields=decoded&received_after=2018-05-22T00:00:00&received_before=2018-05-22T00:01:00
20000 messages
{u'actual': u'20000+', u'after': u'MjAxOC0wNS0yMiAwMDowMDoxOCswMDowMA==', u'limit': 20000, u'before': u'MjAxOC0wNS0yMiAwMDowMTowMCswMDowMA=='}
https://ais.spire.com/messages?fields=decoded&after=MjAxOC0wNS0yMiAwMDowMDoxOCswMDowMA==&before=MjAxOC0wNS0yMiAwMDowMTowMCswMDowMA==
20000 messages
{u'actual': u'20000+', u'after': u'MjAxOC0wNS0yMiAwMDowMTowMCswMDowMA==', u'limit': 20000, u'before': u'MjAxOC0wNS0yMiAwMDowMTowMCswMDowMA=='}
https://ais.spire.com/messages?fields=decoded&after=MjAxOC0wNS0yMiAwMDowMTowMCswMDowMA==&before=MjAxOC0wNS0yMiAwMDowMTowMCswMDowMA==
381 messages
{u'actual': u'381', u'limit': 20000}
The data transfer is over. Thank you.

AIS Messages Older Than & Days

If you attempt to request data older than 7 days from the Messages API, you'll encounter the following error:

Date(s) fall outside of valid date range parameters

Spire AIS Data Archive

We keep data older than 7 days in our AIS archives. They go back as far as June 2016.

If you're interested in archived AIS data, it can be prepared for delivery within file(s) in a CSV or JSON format.

For additional details, please reach out to the Customer Experience team at cx@spire.com

Did this answer your question?