# Panvaya: Ocean container tracking

Public developer guide: https://panvaya.com/developers
OpenAPI 3.1 specification: https://api.panvaya.com/api/v1/openapi.json
Pricing and access: https://panvaya.com/pricing

These examples describe the public API contracts; they do not run requests.
Keep API keys server-side. Both test and live keys can contact real providers and consume credits.
Read the organization's configured product costs and limits before starting a billable workflow.
Example responses are illustrative snapshots, not current shipment or vessel observations.

## API pricing, access and integration

### How much does the Panvaya tracking API cost?
At public default rates, Tracking starts at $10 per 30 days with 20 shared Ocean/Air shipments and 1,200 API credits. Ocean tracking costs 2 credits per successful API response and Air tracking costs 5 by default, including cache hits. Organization-specific rates and product access remain authoritative; check the usage endpoint before a billable workflow.

### Do Web and API tracking use separate shipment allowances?
No. Ocean and Air tracking share one shipment allowance across Web and API. Web refreshes consume no API credits. Successful API calls consume the configured credits even when served from cache, while repeat API tracking of the same enrolled reference in one billing cycle does not add another distinct shipment. API errors are not billed.

### How do I get a container tracking API key?
Sign in to the Panvaya API Dashboard and select Create API key. Choose Sandbox (test) for development or Live for production. Send the key in the X-API-Key header from your server or integration backend. Store it in a secret manager or server-side environment variable.

### Does the sandbox return mock tracking data?
Sandbox keys use the same endpoints, response contracts and workspace limits as live keys. Tracking requests can contact real carriers and consume your workspace's credits and shipment allowance. Use the published JSON examples as fixtures for offline tests. Start with the unbilled GET /api/v1/usage request to verify your key and check available products, configured rates and remaining allowances before trying tracking.

### Are sailing schedules charged per sailing or per carrier?
The public default is 5 credits for each carrier returning usable sailings, regardless of how many sailings that carrier returns. Empty or failed carriers cost zero. Partial and cached results with usable sailings can be billable; your organization's configured price is authoritative.

### How do I connect Panvaya to a TMS or ERP?
Your backend or middleware keeps the API key server-side, calls the documented endpoints and maps the returned JSON to your own shipment records. The integration guide includes shared Ocean/Air request examples, field mappings and starter downloads. Scheduled Ocean webhooks and embedded tracking are also documented. These are integration building blocks, not a claim of a native vendor connector.

### Worked Ocean API example
100 ocean containers checked twice daily
100 containers × 2 checks/day × 30 days × 2 credits = 12,000 credits
At public defaults, 6,000 successful checks use all 12,000 credits in a $100 Tracking allocation. The 100 distinct references use 100 of its 200 shared shipment slots during one billing cycle.

## 1. General Architecture & Authentication
- **Base URL:** `https://api.panvaya.com/api/v1`
- **Authentication:** Pass the API key in the header:
  ```http
  X-API-Key: pv_live_your_key_here
  ```
  (Or as `Authorization: Bearer <key>`). Live keys are prefixed `pv_live_`; sandbox test keys are prefixed `pv_test_`.
- **Content-Type:** `application/json`
- **Rate Limits:** All API keys in one organization share a UTC-minute limit (Free 5, Enterprise 15 requests/minute by default). Each enabled product has a separate organization-wide cap (D&D Tariffs 20; Sailing Schedules 5; Ocean/Air Tracking 10; computational APIs 10; lightweight APIs 10 requests/minute by default). Admins may customize both.
  - Headers returned: `X-Request-Id`, `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and for metered products `X-Product-RateLimit-Limit` and `X-Product-RateLimit-Remaining`.
  - `X-Request-Id` is optional on requests; if omitted, Panvaya generates it and returns it in the response.
  - When throttled, returns `HTTP 429 RATE_LIMIT_EXCEEDED` (organization) or `PRODUCT_RATE_LIMIT_EXCEEDED` (product) with a `Retry-After: <seconds>` header. Integrations should automatically wait and retry.
  - Higher rate limits are available for enterprise accounts on request. Contact Panvaya support to unlock a higher limit.
- **Error Envelope:**
  ```json
  {
    "errors": [
      {
        "code": "INVALID_REQUEST",
        "title": "Invalid request",
        "detail": "One of container, bol, or bk is required."
      }
    ]
  }
  ```
  Always branch on the stable string `code` (e.g. `INVALID_REQUEST`, `CARRIER_NOT_SUPPORTED`, `CARRIER_MAINTENANCE`, `NOT_FOUND`, `QUOTA_EXCEEDED`, `RATE_LIMIT_EXCEEDED`, `PRODUCT_RATE_LIMIT_EXCEEDED`, `RATE_LIMIT_UNAVAILABLE`, `UPSTREAM_ERROR`, `UPSTREAM_UNAVAILABLE`).

## 2. Sea Tracking Normalized Data Model
Panvaya Sea Tracking returns a normalized relational structure to keep payloads compact and efficient:
- `data.locations[]`: Array of ports and facilities (`id`, `name`, `locode`, `coordinates`, `timezone`).
- `data.transports[]`: Array of vessels/vehicles (`id`, `mode`, `name`, `imo`, `call_sign`, `voyage`).
- `data.containers[]`: Array of containers. Each container has:
  - `equipment`: ISO code, length, type, reefer/dry flags.
  - `events[]`: Milestone timeline. Milestones do **NOT** duplicate port or vessel strings. Instead:
    - Match `event.location_id` against `data.locations[].id` to resolve port name and UN/LOCODE.
    - Match `event.transport_id` against `data.transports[].id` to resolve vessel name and IMO.

### Recommended Resolver Snippet (TypeScript / JS):
```typescript
export function enrichTrackingData(data: OceanTrackingResponse['data']) {
  const locationMap = new Map(data.locations.map(l => [l.id, l]));
  const transportMap = new Map(data.transports.map(t => [t.id, t]));

  return data.containers.map(c => ({
    containerNumber: c.number,
    equipment: c.equipment,
    status: c.status,
    events: c.events.map(e => ({
      code: e.event_code,
      name: e.event_name,
      time: e.event_time,
      isActual: e.actual,
      location: locationMap.get(e.location_id),
      transport: transportMap.get(e.transport_id),
    }))
  }));
}
```

### 1) Sea Tracking
- **Method & Path:** `POST /api/v1/track/ocean`
- **Request Body (JSON):**
  - `container` (string, optional): ISO container number (e.g. `"MEDU8611713"`).
  - `bol` (string, optional): Bill of Lading reference. (Mutually exclusive with `bk`).
  - `bk` (string, optional): Booking reference. (Mutually exclusive with `bol`).
  - `shipping_line_scac` (string, optional): Carrier SCAC (e.g. `"MSCU"`) to bypass auto-discovery.
  - `include_route_data` (boolean, default false): Set true to receive a single `path` per route segment, per-leg `status`, aligned `stops[]`, `current_position`, and `ais` vessel telemetry. With false, `data.route_data` is null.
- **Plotting:** Draw each `segments[].path` in GeoJSON `[longitude, latitude]` order and preserve longitudes outside ±180°. Place the marker at `current_position.plot_longitude ?? current_position.longitude` and `current_position.latitude` when present. `source: "live_ais"` identifies the AIS vessel position. Use `estimated` and `observed_at` for marker labels and `ais` for speed, course, heading, and distance to go in nautical miles.
- **Progress styling:** Draw completed legs solid and planned legs dotted. Match `current_position.active_segment_sequence` to `segments[].sequence` and project the position onto the active path. Draw up to that point solid and the rest dotted.
- **Leaflet example**
```js
// Request include_route_data: true. Pass the response JSON to an initialized Leaflet map.
const route = response.data?.route_data;
const layers = L.featureGroup().addTo(map);

for (const { path, status } of route?.segments ?? []) {
  if (!path || path.length < 2) continue;
  const points = path.map(([longitude, latitude]) => [latitude, longitude]);
  L.polyline(points, { dashArray: status === "completed" ? undefined : "6 8" }).addTo(layers);
}

for (const stop of route?.stops ?? []) {
  if (stop.latitude != null && stop.longitude != null) {
    L.circleMarker([stop.latitude, stop.longitude], { radius: 4 }).addTo(layers);
  }
}

const position = route?.current_position;
const longitude = position?.plot_longitude ?? position?.longitude;
const atSea = position?.source === "live_ais" || position?.source === "route_progress";
if (atSea && position.latitude != null && longitude != null) {
  L.marker([position.latitude, longitude]).addTo(layers);
}

const bounds = layers.getBounds();
if (bounds.isValid()) map.fitBounds(bounds, { maxZoom: 9 });
```
- **Example Request:**
```json
{"container":"MEDU8611713","shipping_line_scac":"MSCU","include_route_data":false}
```
- **Errors:** A selected carrier marked under maintenance returns HTTP 503 `CARRIER_MAINTENANCE` in the shared error envelope. Failed requests are not billed.
- **Expanded 200 OK Response (optional route data shown with `include_route_data: true`):**
```json
{
  "data": {
    "reference": {
      "number": "MEDU8611713",
      "type": "container"
    },
    "shipping_line": {
      "scac": "MSCU",
      "name": "Mediterranean Shipping Company (MSC)"
    },
    "status": "in_transit",
    "journey": {
      "origin": null,
      "port_of_lading": {
        "location_id": 1,
        "estimated_departure_at": "2026-10-24T00:00:00",
        "actual_departure_at": null,
        "estimated_arrival_at": null,
        "actual_arrival_at": null
      },
      "port_of_discharge": {
        "location_id": 3,
        "estimated_departure_at": null,
        "actual_departure_at": null,
        "estimated_arrival_at": "2026-11-11T00:00:00",
        "actual_arrival_at": null
      },
      "destination": null
    },
    "locations": [
      {
        "id": 1,
        "name": "Montreal",
        "state": "QC",
        "country": "Canada",
        "country_code": "CA",
        "locode": "CAMTR",
        "latitude": 45.545,
        "longitude": -73.528,
        "timezone": "America/Toronto"
      },
      {
        "id": 2,
        "name": "Gioia Tauro",
        "state": null,
        "country": "Italy",
        "country_code": "IT",
        "locode": "ITGIT",
        "latitude": 38.442,
        "longitude": 15.902,
        "timezone": "Europe/Rome"
      },
      {
        "id": 3,
        "name": "Mersin",
        "state": "33",
        "country": "Türkiye",
        "country_code": "TR",
        "locode": "TRMER",
        "latitude": 36.798,
        "longitude": 34.642,
        "timezone": "Europe/Istanbul"
      }
    ],
    "transports": [
      {
        "id": 1,
        "mode": "truck",
        "name": null,
        "imo": null,
        "call_sign": null,
        "mmsi": null,
        "flag": null,
        "vehicle_number": null,
        "voyage_number": null
      },
      {
        "id": 2,
        "mode": "vessel",
        "name": "MSC KILIMANJARO IV",
        "imo": 9318175,
        "call_sign": "A8JX3",
        "mmsi": 636013001,
        "flag": "LR",
        "vehicle_number": null,
        "voyage_number": "CD643R"
      },
      {
        "id": 3,
        "mode": "vessel",
        "name": "MSC PAMIRA III",
        "imo": 9239903,
        "call_sign": "5LCZ6",
        "mmsi": 636021246,
        "flag": "MH",
        "vehicle_number": null,
        "voyage_number": "AH645R"
      }
    ],
    "containers": [
      {
        "number": "MEDU8611713",
        "equipment": {
          "carrier_code": "40 HIGH CUBE",
          "iso_code": "45G1",
          "description": "High Cube Dry Standard",
          "size": 40,
          "length": "40'",
          "height": "9'6''",
          "width": "8'",
          "bulk": false,
          "liquid": false,
          "reefer": false,
          "high_cube": true,
          "dry": true
        },
        "status": "in_transit",
        "events": [
          {
            "id": 1,
            "location_id": 1,
            "event_code": "PICK",
            "event_name": "Empty equipment picked up",
            "event_category": "equipment",
            "carrier_event_name": "Start Export Cycle",
            "event_time": "2026-10-14T00:00:00",
            "actual": true,
            "transport_id": 1
          },
          {
            "id": 2,
            "location_id": 1,
            "event_code": "GTIN",
            "event_name": "Gate in",
            "event_category": "equipment",
            "carrier_event_name": "Export received at CY",
            "event_time": "2026-10-16T00:00:00",
            "actual": true,
            "transport_id": 1
          },
          {
            "id": 3,
            "location_id": 1,
            "event_code": "DEPA",
            "event_name": "Vessel departed",
            "event_category": "transport",
            "carrier_event_name": "Estimated Time of Departure",
            "event_time": "2026-10-24T00:00:00",
            "actual": false,
            "transport_id": 2
          },
          {
            "id": 4,
            "location_id": 2,
            "event_code": "DISC",
            "event_name": "Discharged at transshipment port",
            "event_category": "equipment",
            "carrier_event_name": "Full Intended Transshipment",
            "event_time": "2026-11-07T00:00:00",
            "actual": false,
            "transport_id": 2
          },
          {
            "id": 5,
            "location_id": 2,
            "event_code": "LOAD",
            "event_name": "Loaded at transshipment port",
            "event_category": "equipment",
            "carrier_event_name": "Full Intended Transshipment",
            "event_time": "2026-11-07T00:00:00",
            "actual": false,
            "transport_id": 3
          },
          {
            "id": 6,
            "location_id": 3,
            "event_code": "ARRI",
            "event_name": "Vessel arrived",
            "event_category": "transport",
            "carrier_event_name": "Estimated Time of Arrival",
            "event_time": "2026-11-11T00:00:00",
            "actual": false,
            "transport_id": 3
          }
        ]
      }
    ],
    "route_data": {
      "segments": [
        {
          "sequence": 1,
          "transport_mode": "vessel",
          "origin_location_id": 1,
          "destination_location_id": 2,
          "transport_id": 2,
          "voyage_number": "CD643R",
          "status": "planned",
          "path": [
            [
              -73.52800000000002,
              45.545
            ],
            [
              -70.375,
              47.375
            ],
            [
              -68.875,
              48.625
            ],
            [
              -66.125,
              49.375
            ],
            [
              -63.875,
              49.375
            ],
            [
              -63.125,
              49.125
            ],
            [
              -61.875,
              48.875
            ],
            [
              -59.125,
              47.375
            ],
            [
              -53.375,
              46.625
            ],
            [
              -8.625,
              36.875
            ],
            [
              -5.875,
              36.125
            ],
            [
              -5.125,
              36.125
            ],
            [
              -1.875,
              36.625
            ],
            [
              15.875,
              38.625
            ],
            [
              15.902000000000044,
              38.442
            ]
          ],
          "path_source": "calculated"
        },
        {
          "sequence": 2,
          "transport_mode": "vessel",
          "origin_location_id": 2,
          "destination_location_id": 3,
          "transport_id": 3,
          "voyage_number": "AH645R",
          "status": "planned",
          "path": [
            [
              15.902000000000044,
              38.442
            ],
            [
              15.875,
              38.625
            ],
            [
              15.625,
              38.375
            ],
            [
              15.625,
              37.875
            ],
            [
              22.375,
              36.625
            ],
            [
              28.625,
              36.625
            ],
            [
              29.375,
              36.125
            ],
            [
              33.375,
              35.875
            ],
            [
              34.625,
              36.625
            ],
            [
              34.64200000000005,
              36.798
            ]
          ],
          "path_source": "calculated"
        }
      ],
      "stops": [
        {
          "sequence": 1,
          "location_id": 1,
          "role": "pol",
          "status": "current",
          "latitude": 45.545,
          "longitude": -73.52800000000002
        },
        {
          "sequence": 2,
          "location_id": 2,
          "role": "transshipment",
          "status": "planned",
          "latitude": 38.442,
          "longitude": 15.902000000000044
        },
        {
          "sequence": 3,
          "location_id": 3,
          "role": "pod",
          "status": "planned",
          "latitude": 36.798,
          "longitude": 34.64200000000005
        }
      ],
      "current_position": {
        "latitude": 45.545,
        "longitude": -73.52800000000002,
        "plot_longitude": -73.52800000000002,
        "source": "last_event",
        "estimated": true,
        "observed_at": null,
        "active_segment_sequence": null
      },
      "ais": {
        "from_cache": null,
        "speed_knots": null,
        "course": null,
        "heading": null,
        "distance_to_go": null,
        "empty": true
      }
    }
  },
  "errors": null
}
```

### 2) List Ocean Carriers
- **Method & Path:** `GET /api/v1/carriers`
- **Description:** Returns all active ocean carriers and SCAC codes for container and document tracking.
- **Example 200 OK Response:**
```json
{
  "mode": "ocean",
  "carriers": [
    {
      "name": "Maersk",
      "code": "MAEU"
    },
    {
      "name": "Mediterranean Shipping Company (MSC)",
      "code": "MSCU"
    },
    {
      "name": "CMA CGM",
      "code": "CMDU"
    },
    {
      "name": "COSCO Shipping Lines",
      "code": "COSU"
    },
    {
      "name": "Hapag-Lloyd",
      "code": "HLCU"
    },
    {
      "name": "Ocean Network Express (ONE)",
      "code": "ONEY"
    },
    {
      "name": "Evergreen Line",
      "code": "EGLV"
    },
    {
      "name": "HMM (Hyundai Merchant Marine)",
      "code": "HDMU"
    },
    {
      "name": "Yang Ming Marine Transport",
      "code": "YMLU"
    },
    {
      "name": "ZIM Integrated Shipping",
      "code": "ZIMU"
    }
  ]
}
```

Full guide: https://panvaya.com/developers/docs.md
