{
  "openapi": "3.1.2",
  "info": {
    "title": "Havnmarq Trade Operations API",
    "version": "1.0.0",
    "description": "Organization-scoped access to shipment records belonging to the one Havnmarq business account linked to an organization, plus read-only discovery of public Copernicus Sentinel-1 scene metadata around a port reference coordinate. Separate keys grant shipment reads, append-only event submission, or satellite-scene discovery. Scene metadata is not a vessel detection or operational port activity signal."
  },
  "servers": [
    {
      "url": "https://core.havnmarq.com"
    }
  ],
  "security": [
    {
      "BearerApiKey": []
    }
  ],
  "paths": {
    "/api/v1/shipments": {
      "get": {
        "operationId": "listShipments",
        "summary": "List shipments in the organization’s linked Havnmarq account",
        "description": "Read-only, organization-scoped list. Every key resolves to an organization and the organization’s one linked Havnmarq client account. Use the opaque next_page_token from the response to retrieve the next page. Per-key limit: 60 requests per minute; organization aggregate limit: 600 requests per minute.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 512
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Shipment page",
            "headers": {
              "RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShipmentPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/satellite/scenes": {
      "get": {
        "operationId": "listSatelliteScenesForPort",
        "summary": "List Sentinel-1 scenes intersecting a port reference coordinate",
        "externalDocs": { "description": "Copernicus Data Space STAC API and data terms", "url": "https://documentation.dataspace.copernicus.eu/APIs/STAC.html" },
        "description": "Requires a satellite:scenes:read key. Havnmarq resolves the UN/LOCODE through its active port master and queries the Copernicus Data Space STAC catalogue for Sentinel-1 GRD acquisitions intersecting that reference point. Results include bounded catalogue footprint geometry when available and a bounding-box fallback; they do not include satellite pixels or establish that the complete operational port boundary was imaged, that vessels were present, or that any movement, congestion, throughput, vessel identity or shipment connection exists. Acquisitions are intermittent, not real time. Maximum 90-day window and 10 scenes per response.",
        "parameters": [
          {
            "name": "unlocode",
            "in": "query",
            "required": true,
            "schema": { "type": "string", "pattern": "^[A-Z]{2}[A-Z0-9]{3}$", "example": "BDCGP" }
          },
          {
            "name": "days",
            "in": "query",
            "required": false,
            "schema": { "type": "integer", "minimum": 1, "maximum": 90, "default": 30 }
          }
        ],
        "responses": {
          "200": {
            "description": "Scene catalogue results and interpretation limits",
            "headers": {
              "RateLimit-Limit": { "schema": { "type": "integer" } },
              "RateLimit-Remaining": { "schema": { "type": "integer" } },
              "RateLimit-Reset": { "schema": { "type": "integer" } }
            },
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SatelliteScenePage" } } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "503": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/v1/shipments/{id}/events": {
      "post": {
        "operationId": "submitShipmentEvent",
        "summary": "Append a customer-authorized shipment event",
        "description": "Requires a shipments:events:write key. The shipment must belong to the key’s organization. Events are append-only and do not change shipment master data. Reuse source and external_event_id for retries: identical content returns the original event; different content returns 409. Havnmarq records source, key, event receipt time and a content hash. This endpoint does not independently verify a carrier feed.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ShipmentEventInput" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Event recorded",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ShipmentEventResponse" } } }
          },
          "200": {
            "description": "Identical event retry; existing event returned",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ShipmentEventResponse" } } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "415": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "503": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Havnmarq API key"
      }
    },
    "schemas": {
      "ShipmentEventInput": {
        "type": "object",
        "required": ["source", "external_event_id", "status", "location", "occurred_at"],
        "properties": {
          "source": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$" },
          "external_event_id": { "type": "string", "minLength": 1, "maxLength": 128 },
          "status": { "type": "string", "minLength": 1, "maxLength": 80 },
          "location": { "type": "string", "minLength": 1, "maxLength": 160 },
          "occurred_at": { "type": "string", "format": "date-time" }
        },
        "additionalProperties": false
      },
      "GeoJSONPosition": {
        "type": "array",
        "items": { "type": "number" },
        "minItems": 2,
        "maxItems": 2
      },
      "SatelliteScene": {
        "type": "object",
        "required": ["id", "acquired_at", "product_type", "platform", "orbit_direction", "relative_orbit", "polarizations", "footprint_bbox", "footprint", "catalog_url"],
        "properties": {
          "id": { "type": "string" },
          "acquired_at": { "type": "string", "format": "date-time" },
          "product_type": { "type": ["string", "null"] },
          "platform": { "type": ["string", "null"] },
          "orbit_direction": { "type": ["string", "null"], "enum": ["ascending", "descending", null] },
          "relative_orbit": { "type": ["integer", "null"] },
          "polarizations": { "type": "array", "items": { "type": "string" } },
          "footprint_bbox": { "type": ["array", "null"], "items": { "type": "number" }, "minItems": 4, "maxItems": 4 },
          "footprint": {
            "oneOf": [
              { "type": "null" },
              {
                "type": "object",
                "required": ["type", "coordinates"],
                "properties": {
                  "type": { "const": "Polygon" },
                  "coordinates": { "type": "array", "minItems": 1, "maxItems": 8, "items": { "type": "array", "minItems": 4, "maxItems": 128, "items": { "$ref": "#/components/schemas/GeoJSONPosition" } } }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "required": ["type", "coordinates"],
                "properties": {
                  "type": { "const": "MultiPolygon" },
                  "coordinates": { "type": "array", "minItems": 1, "maxItems": 4, "items": { "type": "array", "minItems": 1, "maxItems": 8, "items": { "type": "array", "minItems": 4, "maxItems": 128, "items": { "$ref": "#/components/schemas/GeoJSONPosition" } } } }
                },
                "additionalProperties": false
              }
            ]
          },
          "catalog_url": { "type": "string", "format": "uri" }
        },
        "additionalProperties": false
      },
      "SatelliteScenePage": {
        "type": "object",
        "required": ["data", "meta"],
        "properties": {
          "data": { "type": "array", "maxItems": 10, "items": { "$ref": "#/components/schemas/SatelliteScene" } },
          "meta": {
            "type": "object",
            "required": ["request_id", "source", "collection", "port", "query_geometry", "window_days", "scene_limit", "source_checked_at", "cache_status", "limitations"],
            "properties": {
              "request_id": { "type": "string", "format": "uuid" },
              "source": { "type": "string" },
              "collection": { "type": "string", "const": "sentinel-1-grd" },
              "port": { "type": "object", "required": ["unlocode", "name", "country"], "properties": { "unlocode": { "type": "string" }, "name": { "type": "string" }, "country": { "type": ["string", "null"] } }, "additionalProperties": false },
              "query_geometry": { "type": "string" },
              "window_days": { "type": "integer" },
              "scene_limit": { "type": "integer", "const": 10 },
              "source_checked_at": { "type": "string", "format": "date-time" },
              "cache_status": { "type": "string", "enum": ["shared_cache", "refreshed", "uncached"] },
              "limitations": { "type": "array", "items": { "type": "string" } }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "ShipmentEventResponse": {
        "type": "object",
        "required": ["data", "meta"],
        "properties": {
          "data": {
            "type": "object",
            "required": ["id", "shipment_id", "source", "external_event_id", "occurred_at"],
            "properties": {
              "id": { "type": "string", "format": "uuid" },
              "shipment_id": { "type": "string", "format": "uuid" },
              "source": { "type": "string" },
              "external_event_id": { "type": "string" },
              "occurred_at": { "type": "string", "format": "date-time" }
            },
            "additionalProperties": false
          },
          "meta": {
            "type": "object",
            "required": ["duplicate", "received_at", "request_id"],
            "properties": {
              "duplicate": { "type": "boolean" },
              "received_at": { "type": "string", "format": "date-time" },
              "request_id": { "type": "string", "format": "uuid" }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "Shipment": {
        "type": "object",
        "required": [
          "id",
          "mode",
          "origin",
          "destination",
          "container_or_awb_number",
          "current_status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "mode": {
            "type": "string",
            "enum": [
              "Sea",
              "Air",
              "Road"
            ]
          },
          "origin": {
            "type": "string"
          },
          "destination": {
            "type": "string"
          },
          "carrier": {
            "type": [
              "string",
              "null"
            ]
          },
          "container_or_awb_number": {
            "type": "string"
          },
          "current_status": {
            "type": "string"
          },
          "eta": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "additionalProperties": false
      },
      "ShipmentPage": {
        "type": "object",
        "required": [
          "data",
          "meta"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Shipment"
            }
          },
          "meta": {
            "type": "object",
            "required": [
              "limit",
              "next_page_token",
              "request_id"
            ],
            "properties": {
              "limit": {
                "type": "integer"
              },
              "next_page_token": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "request_id": {
                "type": "string",
                "format": "uuid"
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    },
    "responses": {
      "Error": {
        "description": "Request failed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      }
    }
  }
}
