Official Integrations
The Data Docked API is a REST API that works with any HTTP client. Here are examples for popular languages and frameworks.- Python
- JavaScript
- Go
- cURL
Installation
Use therequests library for HTTP calls:Copy
Ask AI
pip install requests
Usage
Copy
Ask AI
import requests
API_KEY = "your_api_key"
BASE_URL = "https://datadocked.com/api/vessels_operations"
def get_vessel_location(imo_or_mmsi: str) -> dict:
response = requests.get(
f"{BASE_URL}/get-vessel-location",
params={"imo_or_mmsi": imo_or_mmsi},
headers={"x-api-key": API_KEY}
)
return response.json()
# Track a vessel
vessel = get_vessel_location("9247431")
print(f"Vessel: {vessel['detail']['name']}")
print(f"Position: {vessel['detail']['latitude']}, {vessel['detail']['longitude']}")
Async with httpx
Copy
Ask AI
import httpx
import asyncio
async def get_vessel_location_async(imo_or_mmsi: str) -> dict:
async with httpx.AsyncClient() as client:
response = await client.get(
f"{BASE_URL}/get-vessel-location",
params={"imo_or_mmsi": imo_or_mmsi},
headers={"x-api-key": API_KEY}
)
return response.json()
# Run async
vessel = asyncio.run(get_vessel_location_async("9247431"))
Node.js
Copy
Ask AI
const API_KEY = 'your_api_key';
const BASE_URL = 'https://datadocked.com/api/vessels_operations';
async function getVesselLocation(imoOrMmsi) {
const response = await fetch(
`${BASE_URL}/get-vessel-location?imo_or_mmsi=${imoOrMmsi}`,
{
headers: {
'x-api-key': API_KEY,
'Accept': 'application/json'
}
}
);
return response.json();
}
// Track a vessel
const vessel = await getVesselLocation('9247431');
console.log(`Vessel: ${vessel.detail.name}`);
console.log(`Position: ${vessel.detail.latitude}, ${vessel.detail.longitude}`);
With Axios
Copy
Ask AI
import axios from 'axios';
const client = axios.create({
baseURL: 'https://datadocked.com/api/vessels_operations',
headers: { 'x-api-key': API_KEY }
});
const { data } = await client.get('/get-vessel-location', {
params: { imo_or_mmsi: '9247431' }
});
Usage
Copy
Ask AI
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
)
const (
apiKey = "your_api_key"
baseURL = "https://datadocked.com/api/vessels_operations"
)
type VesselLocation struct {
Detail struct {
Name string `json:"name"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
Speed string `json:"speed"`
} `json:"detail"`
}
func getVesselLocation(imoOrMMSI string) (*VesselLocation, error) {
endpoint := fmt.Sprintf("%s/get-vessel-location?imo_or_mmsi=%s",
baseURL, url.QueryEscape(imoOrMMSI))
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Set("x-api-key", apiKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var vessel VesselLocation
json.Unmarshal(body, &vessel)
return &vessel, nil
}
func main() {
vessel, _ := getVesselLocation("9247431")
fmt.Printf("Vessel: %s\n", vessel.Detail.Name)
fmt.Printf("Position: %s, %s\n", vessel.Detail.Latitude, vessel.Detail.Longitude)
}
Basic Request
Copy
Ask AI
curl -X GET "https://datadocked.com/api/vessels_operations/get-vessel-location?imo_or_mmsi=9247431" \
-H "x-api-key: YOUR_API_KEY" \
-H "Accept: application/json"
With jq for Parsing
Copy
Ask AI
curl -s "https://datadocked.com/api/vessels_operations/get-vessel-location?imo_or_mmsi=9247431" \
-H "x-api-key: YOUR_API_KEY" | jq '.detail | {name, latitude, longitude}'
Bulk Search
Copy
Ask AI
curl -X GET "https://datadocked.com/api/vessels_operations/get-vessels-location-bulk-search?imo_or_mmsi=9465411,215767000,9247431" \
-H "x-api-key: YOUR_API_KEY"
Helper Functions
Python: Complete API Client
Copy
Ask AI
import requests
from typing import Optional, List
from dataclasses import dataclass
@dataclass
class DataDockedClient:
api_key: str
base_url: str = "https://datadocked.com/api/vessels_operations"
def _request(self, endpoint: str, params: dict = None) -> dict:
response = requests.get(
f"{self.base_url}/{endpoint}",
params=params,
headers={"x-api-key": self.api_key}
)
response.raise_for_status()
return response.json()
def get_credits(self) -> str:
return self._request("my-credits")["detail"]
def get_vessel_location(self, imo_or_mmsi: str) -> dict:
return self._request("get-vessel-location", {"imo_or_mmsi": imo_or_mmsi})
def get_vessel_info(self, imo_or_mmsi: str) -> dict:
return self._request("get-vessel-info", {"imo_or_mmsi": imo_or_mmsi})
def bulk_location_search(self, identifiers: List[str]) -> dict:
return self._request("get-vessels-location-bulk-search",
{"imo_or_mmsi": ",".join(identifiers)})
def get_port_calls(self, imo_or_mmsi: str) -> dict:
return self._request("port-calls-by-vessel", {"imo_or_mmsi": imo_or_mmsi})
# Usage
client = DataDockedClient(api_key="your_api_key")
print(client.get_credits())
vessel = client.get_vessel_location("9247431")
Rate Limiting
Implement exponential backoff for production use:Copy
Ask AI
import time
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
def create_session(api_key: str) -> requests.Session:
session = requests.Session()
session.headers["x-api-key"] = api_key
retries = Retry(
total=3,
backoff_factor=1,
status_forcelist=[429, 500, 502, 503, 504]
)
session.mount("https://", HTTPAdapter(max_retries=retries))
return session
session = create_session("your_api_key")
response = session.get("https://datadocked.com/api/vessels_operations/get-vessel-location",
params={"imo_or_mmsi": "9247431"})
Environment Variables
Store your API key securely:Copy
Ask AI
DATADOCKED_API_KEY=your_api_key_here