Datalastic Maritime API Logo

Setting Up Automated Ship Arrival Alerts with Datalastic API

Maritime API

Setting Up Automated Ship Arrival Alerts with Datalastic API

Real-time vessel monitoring is crucial for maritime operations, logistics planning, and supply chain management. Whether you’re tracking your own fleet or monitoring vessel arrivals at specific ports, having automated alerts can save time and improve operational efficiency. In this guide, I’ll show you how to use Datalastic’s API to set up real-time vessel alerts when ships reach specific ports.

Project Overview: Why Build Automated Ship Arrival Alerts?

This project creates an automated monitoring system that uses Datalastic’s powerful ship tracking API to notify you when vessels of interest arrive at designated ports.

Our system will:

  • Track vessels of your choice using their unique identifiers (MMSI, IMO, or UUID)
  • Monitor their positions and status in real-time
  • Detect when a vessel has arrived at a port of interest
  • Send immediate alerts through your preferred notification channels

Whether you’re a port authority needing to prepare berths, a logistics coordinator planning cargo transfers, or a shipping company tracking your fleet, this system eliminates the need for manual vessel checking and provides critical information exactly when you need it.

The complete solution requires minimal setup and runs continuously in the background, allowing your team to focus on responding to events rather than constantly searching for updates.

Port tracking Map

Tools You Need to Build Ship Arrival Alert System:

  • A Datalastic API key: You can get your own API key is less than 5minutes!

  • Some basic Python skills: Nothing too fancy. If you’ve used requests and loops before, you’re good.

How Datalastic’s API Powers Real-Time Ship Arrival Alerts?

With our Pro Live Ship Tracking API endpoint provides real-time access to vessel positions worldwide.

This endpoint is perfect for creating custom alert systems since it gives you access to current vessel locations, destinations, ETAs, and more detailed vessel information.

Step-by-Step Implementation:

1. Set Up Your Python Environment for Alert Monitoring

First, let’s set up a Python environment with the necessary libraries:

import requests
import time
import json
from datetime import datetime
from geopy.distance import geodesic

2. Choose Ports to Monitor for Ship Arrivals

Create a list of ports you want to monitor. For each port, you’ll need its name and coordinates:

target_ports = [
 {"name": "Rotterdam", "coordinates": (51.9225, 4.47917), "unlocode": "NLRTM"},
 {"name": "Singapore", "coordinates": (1.29027, 103.851), "unlocode": "SGSIN"},
 {"name": "Shanghai", "coordinates": (31.2304, 121.4737), "unlocode": "CNSHA"}
]

3. Create a Function to Check Vessel Proximity to Ports

This function will determine if a vessel is within a certain distance of any monitored port:

def is_vessel_at_port(vessel_position, port_coordinates, threshold_km=5):
 """Check if vessel is within threshold distance of port"""
 vessel_coords = (vessel_position['lat'], vessel_position['lon'])
 distance = geodesic(vessel_coords, port_coordinates).kilometers
 return distance <= threshold_km

4. Set Up the Vessel Monitoring System

Now, let’s create the main monitoring function that will track vessels and trigger alerts:

def monitor_vessels(api_key, vessel_identifiers, check_interval=300):
 """
 Monitor vessels and alert when they reach a target port 
 Parameters:
 - api_key: Your Datalastic API key
 - vessel_identifiers: Dictionary mapping vessel IDs to their type (mmsi, imo, or uuid)
 - check_interval: Time between checks in seconds (default 5 minutes)
 """
 # Track which vessels have already triggered alerts
 alerted_vessels = {} 
 while True:
 for vessel_id, id_type in vessel_identifiers.items():
 try:
 # Call Datalastic Pro Live Ship Tracking API
 response = requests.get(
 f"https://api.datalastic.com/api/v0/vessel_pro",
 params={"api-key": api_key, id_type: vessel_id}
 ) 
 data = response.json() 
 if "data" in data:
 vessel = data["data"]
 vessel_name = vessel.get("name", f"{id_type.upper()}:{vessel_id}")
 position = {"lat": vessel["lat"], "lon": vessel["lon"]} 
 # Get destination information
 destination = vessel.get("destination", "")
 dest_port = vessel.get("dest_port", "")
 dest_unlocode = vessel.get("dest_port_unlocode", "") 
 # Check if vessel is at any monitored port
 for port in target_ports:
 # Check both by coordinates and by destination UNLOCODE
 vessel_port_key = f"{vessel_id}-{port['name']}" 
 at_port_by_location = is_vessel_at_port(position, port["coordinates"])
 at_port_by_unlocode = dest_unlocode == port["unlocode"] and vessel["speed"] < 1 
 if ((at_port_by_location or at_port_by_unlocode) and 
 vessel_port_key not in alerted_vessels):
 # Trigger alert
 send_alert(vessel_name, vessel_id, id_type, port["name"], vessel)
 alerted_vessels[vessel_port_key] = time.time() 
 # Reset alert status if vessel leaves port (optional)
 elif (vessel_port_key in alerted_vessels and 
 not at_port_by_location and 
 vessel["speed"] > 3):  # Ship is moving away
 del alerted_vessels[vessel_port_key] 
 except Exception as e:
 print(f"Error monitoring vessel {id_type}:{vessel_id}: {e}") 
 # Wait before next check
 time.sleep(check_interval)

5. Define Alert Messages for Ship Arrivals

Define how you want to be notified when a vessel arrives at a port:

def send_alert(vessel_name, vessel_id, id_type, port_name, vessel_data):
 """Send an alert when vessel arrives at port"""
 arrival_time = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC") 
 message = f"""
VESSEL ARRIVAL ALERT
--------------------
Vessel: {vessel_name}
{id_type.upper()}: {vessel_id}
Port: {port_name}
Arrival Time: {arrival_time}
Status: {vessel_data.get('navigational_status', 'Unknown')}
Current Draught: {vessel_data.get('current_draught', 'Unknown')}
Destination: {vessel_data.get('destination', 'Unknown')}
 """ 
 # Print to console
 print(message) 
 # Here you can implement your preferred notification method:
 # send_email(message)
 # send_sms(message)
 # send_slack_notification(message)
 # send_webhook(vessel_data)

6. Implement Notification Methods

Here’s an example of sending email notifications:

import smtplib
from email.message import EmailMessage
def send_email(message_body, recipient="alerts@yourcompany.com"):
 """Send email alert"""
 msg = EmailMessage()
 msg.set_content(message_body) 
 msg['Subject'] = 'Vessel Port Arrival Alert'
 msg['From'] = 'vessel-alerts@yourcompany.com'
 msg['To'] = recipient 
 # Connect to SMTP server and send
 server = smtplib.SMTP('smtp.yourcompany.com', 587)
 server.starttls()
 server.login('username', 'password')
 server.send_message(msg)
 server.quit()

7. Run the Complete Ship Arrival Alert System

Now let’s create the main script to run our vessel monitoring system:

if __name__ == "__main__":
 # Your Datalastic API key
 API_KEY = "your_api_key_here" 
 # List of vessel identifiers to monitor
 # You can use any combination of mmsi, imo, or uuid
 vessels_to_monitor = {
 "566093000": "mmsi",    # MAERSK CHENNAI
 "9525338": "imo",       # MAERSK CHENNAI (alternative identifier)
 "b8625b67-7142-cfd1-7b85-595cebfe4191": "uuid"  # MAERSK CHENNAI (uuid)
 } 
 # Start monitoring (checks every 10 minutes)
 monitor_vessels(API_KEY, vessels_to_monitor, check_interval=600)

Deploying and Scaling Your Ship Arrival Notification System:

Once everything works smoothly in your test environment, here are a few things to keep in mind before putting it into production:

  • Stay online: Run your alert system on a reliable cloud service with good uptime, so you don’t miss any arrivals.

  • Handle hiccups: Make sure to catch errors and log them properly—this saves headaches when something goes wrong.

  • Watch your limits: Datalastic has API rate limits of 600 API calls per minute, so be mindful of how often you ping their servers.

Why Automated Ship Arrival Alerts Improve Maritime Operations?

By leveraging Datalastic’s Live Ship Tracking API, you can build a robust real-time alert system for vessel port arrivals. This can significantly enhance your maritime operations, improve logistics planning, and provide valuable insights for your business.

Remember to check our API documentation for the most current endpoint details and usage limits when implementing your solution.

Read Other Maritime Articles 

Maritime Weather API: Current and Hourly Data

Maritime Weather API: Current and Hourly Data

If you've ever tried to bolt weather data onto a shipping or logistics tool, you know the annoying part isn't the weather data itself. It's that marine conditions and atmospheric conditions usually come from two different providers with two different schemas, and...

AIS Spoofing in the Red Sea: What’s Really Happening

AIS Spoofing in the Red Sea: What’s Really Happening

A cargo ship off Yanbu suddenly reports a position it couldn’t possibly have reached. Its speed jumps to 45 knots, far beyond what a loaded tanker can realistically do. Minutes later, the signal disappears. Hours after that, the vessel reappears somewhere else...

How To Use ChatGPT To Track Ships in Real Time?

How To Use ChatGPT To Track Ships in Real Time?

Tracking ships using ChatGPT is possible and an easy process when it is connected to a live maritime data source such as Datalastic. On its own, ChatGPT does not maintain a live database of ship positions. It may know general information about vessels, shipping...

How to Connect Datalastic to Claude and ChatGPT?

How to Connect Datalastic to Claude and ChatGPT?

Connecting Datalastic to Claude and ChatGPT is an easy and fast process that you'll be surprised by it, following this tutorial. By connecting Datalastic through its Model Context Protocol (MCP) server, you can give AI assistants direct access to real-time maritime...

Find Vessels In The Gulf Of Oman

Find Vessels In The Gulf Of Oman

Tracking vessels in the Gulf of Oman is essential for understanding maritime traffic in one of the world’s most strategically important shipping corridors. This region connects the Arabian Sea with the Strait of Hormuz, acting as a gateway for global oil shipments,...

Enterprise Vessel Tracking API

Enterprise Vessel Tracking API

An enterprise vessel tracking API is not defined by features alone. It is defined by scale, reliability, and the ability to perform under real-world pressure. In maritime operations, where systems rely on continuous data flows, even small inefficiencies can quickly...