> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datadocked.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SDKs & Libraries

> Integrate Data Docked API into your applications

## Official Integrations

The Data Docked API is a REST API that works with any HTTP client. Here are examples for popular languages and frameworks.

<Tabs>
  <Tab title="Python">
    ### Installation

    Use the `requests` library for HTTP calls:

    ```bash theme={null}
    pip install requests
    ```

    ### Usage

    ```python theme={null}
    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

    ```python theme={null}
    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"))
    ```
  </Tab>

  <Tab title="JavaScript">
    ### Node.js

    ```javascript theme={null}
    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

    ```javascript theme={null}
    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' }
    });
    ```
  </Tab>

  <Tab title="Go">
    ### Usage

    ```go theme={null}
    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)
    }
    ```
  </Tab>

  <Tab title="cURL">
    ### Basic Request

    ```bash theme={null}
    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

    ```bash theme={null}
    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

    ```bash theme={null}
    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"
    ```
  </Tab>
</Tabs>

***

## Helper Functions

### Python: Complete API Client

```python theme={null}
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:

```python theme={null}
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:

<CodeGroup>
  ```bash .env theme={null}
  DATADOCKED_API_KEY=your_api_key_here
  ```

  ```python Python theme={null}
  import os
  api_key = os.environ.get("DATADOCKED_API_KEY")
  ```

  ```javascript Node.js theme={null}
  const apiKey = process.env.DATADOCKED_API_KEY;
  ```

  ```go Go theme={null}
  apiKey := os.Getenv("DATADOCKED_API_KEY")
  ```
</CodeGroup>
