{
  "openapi": "3.1.0",
  "info": {
    "title": "Outturn public API",
    "summary": "Push records into Outturn and read findings out of it.",
    "description": "Authenticate with a workspace API key created in Settings -> Developers: `Authorization: Bearer otk_...`. All requests are over HTTPS. Errors have the shape `{\"error\": {\"code\": \"...\", \"message\": \"...\"}}`.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://outturn.eu",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/public/v1/ping": {
      "get": {
        "tags": [
          "Public API"
        ],
        "summary": "Check your key",
        "description": "Returns the workspace and the scopes of the key you are calling with.",
        "operationId": "ping_api_public_v1_ping_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PingOut"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/api/public/v1/record-types": {
      "get": {
        "tags": [
          "Public API"
        ],
        "summary": "List the record types you can send",
        "operationId": "record_types_api_public_v1_record_types_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "additionalProperties": true,
                    "type": "object"
                  },
                  "type": "array",
                  "title": "Response Record Types Api Public V1 Record Types Get"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/api/public/v1/records": {
      "post": {
        "tags": [
          "Public API"
        ],
        "summary": "Send records (idempotent)",
        "description": "Send a batch of records of one documented type. The whole batch is checked first: if any\nrecord is invalid the response is 422 with every problem and nothing is written.",
        "operationId": "post_records_api_public_v1_records_post",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Required. 1-128 characters from A-Z a-z 0-9 . _ : -. A retry with the same key and body returns the first response.",
              "title": "Idempotency-Key"
            },
            "description": "Required. 1-128 characters from A-Z a-z 0-9 . _ : -. A retry with the same key and body returns the first response."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestResult"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON or Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "402": {
            "description": "The workspace is read-only.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency-Key reused with a different body.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "413": {
            "description": "Body or batch too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "422": {
            "description": "Some records are invalid; nothing was written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationFailed"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecordsRequest"
              }
            }
          }
        }
      }
    },
    "/api/public/v1/findings": {
      "get": {
        "tags": [
          "Public API"
        ],
        "summary": "List findings",
        "description": "Findings of your workspace, oldest detection first. Page with ``next_cursor``.",
        "operationId": "list_findings_api_public_v1_findings_get",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "One of OPEN, ACKNOWLEDGED, RESOLVED, DISMISSED, CHECKED_OK.",
              "title": "Status"
            },
            "description": "One of OPEN, ACKNOWLEDGED, RESOLVED, DISMISSED, CHECKED_OK."
          },
          {
            "name": "severity",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "One of INFO, LOW, MEDIUM, HIGH, CRITICAL.",
              "title": "Severity"
            },
            "description": "One of INFO, LOW, MEDIUM, HIGH, CRITICAL."
          },
          {
            "name": "department",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "One of VESSEL, GATE, WEIGHBRIDGE, RAIL, WAREHOUSE, LAB, CUSTOMS, COMMERCIAL, FINANCE, HSE, MANAGEMENT.",
              "title": "Department"
            },
            "description": "One of VESSEL, GATE, WEIGHBRIDGE, RAIL, WAREHOUSE, LAB, CUSTOMS, COMMERCIAL, FINANCE, HSE, MANAGEMENT."
          },
          {
            "name": "detected_since",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Only findings detected at or after this instant (RFC 3339).",
              "title": "Detected Since"
            },
            "description": "Only findings detected at or after this instant (RFC 3339)."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Opaque value from next_cursor.",
              "title": "Cursor"
            },
            "description": "Opaque value from next_cursor."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 200,
              "minimum": 1,
              "default": 50,
              "title": "Limit"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FindingsPage"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/findings/{finding_id}": {
      "get": {
        "tags": [
          "Public API"
        ],
        "summary": "Get one finding",
        "operationId": "get_finding_api_public_v1_findings__finding_id__get",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "finding_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "title": "Finding Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicFinding"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "404": {
            "description": "No such finding.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorOut"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorBody": {
        "properties": {
          "code": {
            "type": "string",
            "title": "Code"
          },
          "message": {
            "type": "string",
            "title": "Message"
          }
        },
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "title": "ErrorBody"
      },
      "ErrorOut": {
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorBody"
          }
        },
        "type": "object",
        "required": [
          "error"
        ],
        "title": "ErrorOut"
      },
      "FindingMoney": {
        "properties": {
          "amount": {
            "type": "string",
            "title": "Amount"
          },
          "currency": {
            "type": "string",
            "title": "Currency"
          }
        },
        "type": "object",
        "required": [
          "amount",
          "currency"
        ],
        "title": "FindingMoney"
      },
      "FindingsPage": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/PublicFinding"
            },
            "type": "array",
            "title": "Items"
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Next Cursor"
          }
        },
        "type": "object",
        "required": [
          "items",
          "next_cursor"
        ],
        "title": "FindingsPage"
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "IngestResult": {
        "properties": {
          "request_id": {
            "type": "string",
            "title": "Request Id"
          },
          "record_type": {
            "type": "string",
            "title": "Record Type"
          },
          "accepted": {
            "type": "integer",
            "title": "Accepted"
          },
          "facts_written": {
            "additionalProperties": {
              "type": "integer"
            },
            "type": "object",
            "title": "Facts Written"
          },
          "note": {
            "type": "string",
            "title": "Note"
          }
        },
        "type": "object",
        "required": [
          "request_id",
          "record_type",
          "accepted",
          "facts_written",
          "note"
        ],
        "title": "IngestResult"
      },
      "PingOut": {
        "properties": {
          "api_version": {
            "type": "string",
            "title": "Api Version"
          },
          "workspace": {
            "type": "string",
            "title": "Workspace"
          },
          "key_name": {
            "type": "string",
            "title": "Key Name"
          },
          "key_prefix": {
            "type": "string",
            "title": "Key Prefix"
          },
          "scopes": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Scopes"
          },
          "rate_limit_per_minute": {
            "type": "integer",
            "title": "Rate Limit Per Minute"
          }
        },
        "type": "object",
        "required": [
          "api_version",
          "workspace",
          "key_name",
          "key_prefix",
          "scopes",
          "rate_limit_per_minute"
        ],
        "title": "PingOut"
      },
      "PublicFinding": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "rule_id": {
            "type": "string",
            "title": "Rule Id"
          },
          "rule_version": {
            "type": "string",
            "title": "Rule Version"
          },
          "title": {
            "type": "string",
            "title": "Title"
          },
          "severity": {
            "type": "string",
            "title": "Severity"
          },
          "classification": {
            "type": "string",
            "title": "Classification"
          },
          "department": {
            "type": "string",
            "title": "Department"
          },
          "status": {
            "type": "string",
            "title": "Status"
          },
          "money_at_stake": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/FindingMoney"
              },
              {
                "type": "null"
              }
            ]
          },
          "explanation": {
            "type": "string",
            "title": "Explanation"
          },
          "entities": {
            "items": {
              "additionalProperties": true,
              "type": "object"
            },
            "type": "array",
            "title": "Entities"
          },
          "inputs": {
            "additionalProperties": true,
            "type": "object",
            "title": "Inputs"
          },
          "tolerances": {
            "items": {
              "additionalProperties": true,
              "type": "object"
            },
            "type": "array",
            "title": "Tolerances"
          },
          "delta": {
            "additionalProperties": true,
            "type": "object",
            "title": "Delta"
          },
          "citations": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Citations"
          },
          "detected_at": {
            "type": "string",
            "title": "Detected At"
          },
          "url": {
            "type": "string",
            "title": "Url"
          }
        },
        "type": "object",
        "required": [
          "id",
          "rule_id",
          "rule_version",
          "title",
          "severity",
          "classification",
          "department",
          "status",
          "money_at_stake",
          "explanation",
          "entities",
          "inputs",
          "tolerances",
          "delta",
          "citations",
          "detected_at",
          "url"
        ],
        "title": "PublicFinding"
      },
      "RecordProblem": {
        "properties": {
          "index": {
            "type": "integer",
            "title": "Index"
          },
          "external_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "External Id"
          },
          "field": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Field"
          },
          "code": {
            "type": "string",
            "title": "Code"
          },
          "message": {
            "type": "string",
            "title": "Message"
          }
        },
        "type": "object",
        "required": [
          "index",
          "external_id",
          "field",
          "code",
          "message"
        ],
        "title": "RecordProblem"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          },
          "input": {
            "title": "Input"
          },
          "ctx": {
            "type": "object",
            "title": "Context"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      },
      "ValidationFailed": {
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorBody"
          },
          "errors": {
            "items": {
              "$ref": "#/components/schemas/RecordProblem"
            },
            "type": "array",
            "title": "Errors"
          },
          "errors_truncated": {
            "type": "boolean",
            "title": "Errors Truncated"
          }
        },
        "type": "object",
        "required": [
          "error",
          "errors",
          "errors_truncated"
        ],
        "title": "ValidationFailed"
      },
      "Record_weighbridge_ticket": {
        "type": "object",
        "title": "Weighbridge ticket",
        "description": "One weighing ticket. Send the gross, tare and/or net weight you have. At least one of: gross_kg, tare_kg, net_kg.",
        "required": [
          "external_id",
          "ticket_no",
          "measured_at"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own unique id for this record."
          },
          "ticket_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Ticket number as printed by the scale software."
          },
          "measured_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the weighing happened (RFC 3339, with offset)."
          },
          "gross_kg": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Gross weight in kilograms."
          },
          "tare_kg": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Tare weight in kilograms."
          },
          "net_kg": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Net weight in kilograms."
          },
          "tractor_plate": {
            "type": "string",
            "maxLength": 120,
            "description": "Tractor plate as read at the gate."
          },
          "trailer_plate": {
            "type": "string",
            "maxLength": 120,
            "description": "Trailer plate."
          },
          "lot_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Cargo lot the weighing belongs to."
          },
          "booking_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Booking or order number."
          },
          "instrument": {
            "type": "string",
            "maxLength": 120,
            "description": "Scale identifier."
          },
          "contractual_status": {
            "type": "string",
            "maxLength": 120,
            "enum": [
              "CONTRACTUAL",
              "INFORMATION_ONLY"
            ],
            "description": "CONTRACTUAL if this is the terminal's billing weight, otherwise INFORMATION_ONLY."
          }
        },
        "additionalProperties": false,
        "example": {
          "external_id": "WB-2026-000123",
          "ticket_no": "000123",
          "measured_at": "2026-10-08T07:30:00+03:00",
          "gross_kg": "41250",
          "tare_kg": "15310",
          "net_kg": "25940",
          "tractor_plate": "ABC123",
          "lot_code": "LOT-WHEAT-0007"
        }
      },
      "Record_wagon_visit": {
        "type": "object",
        "title": "Wagon visit",
        "description": "One wagon on a train: identity, arrival and the rail-desk milestones.",
        "required": [
          "external_id",
          "wagon_no"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own unique id for this record."
          },
          "wagon_no": {
            "type": "string",
            "maxLength": 120,
            "description": "12-digit UIC (check digit validated) or 8-digit 1520 wagon number."
          },
          "train_ref": {
            "type": "string",
            "maxLength": 120,
            "description": "Train number or reference."
          },
          "consignment_note_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Consignment note (CIM/SMGS) number."
          },
          "lot_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Cargo lot carried."
          },
          "arrived_at": {
            "type": "string",
            "format": "date-time",
            "description": "Arrival at the terminal."
          },
          "departed_at": {
            "type": "string",
            "format": "date-time",
            "description": "Departure."
          },
          "placement_at": {
            "type": "string",
            "format": "date-time",
            "description": "Placement of the train at the loading/unloading track."
          },
          "acceptance_at": {
            "type": "string",
            "format": "date-time",
            "description": "Acceptance of the train by the terminal."
          },
          "completed_at": {
            "type": "string",
            "format": "date-time",
            "description": "Completion of loading or unloading."
          },
          "documents_handed_over_at": {
            "type": "string",
            "format": "date-time",
            "description": "Documents handed over to the carrier."
          },
          "waybill_mass_kg": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Mass declared on the waybill, kilograms."
          }
        },
        "additionalProperties": false,
        "example": {
          "external_id": "WAGON-2026-10-08-0001",
          "wagon_no": "315600270120",
          "train_ref": "T-4412",
          "arrived_at": "2026-10-08T05:10:00+03:00",
          "placement_at": "2026-10-08T06:00:00+03:00"
        }
      },
      "Record_truck_visit": {
        "type": "object",
        "title": "Truck visit",
        "description": "One truck passing the gate.",
        "required": [
          "external_id"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own unique id for this record."
          },
          "booking_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Booking or order number."
          },
          "tractor_plate": {
            "type": "string",
            "maxLength": 120,
            "description": "Tractor plate."
          },
          "trailer_plate": {
            "type": "string",
            "maxLength": 120,
            "description": "Trailer plate."
          },
          "cmr_no": {
            "type": "string",
            "maxLength": 120,
            "description": "CMR number."
          },
          "lot_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Cargo lot."
          },
          "arrived_at": {
            "type": "string",
            "format": "date-time",
            "description": "Gate-in time."
          },
          "departed_at": {
            "type": "string",
            "format": "date-time",
            "description": "Gate-out time."
          }
        },
        "additionalProperties": false,
        "example": {
          "external_id": "GATE-2026-10-08-0042",
          "booking_no": "BK-77123",
          "tractor_plate": "ABC123",
          "arrived_at": "2026-10-08T07:05:00+03:00"
        }
      },
      "Record_vessel_call": {
        "type": "object",
        "title": "Vessel call",
        "description": "One vessel call with its operational timestamps.",
        "required": [
          "external_id",
          "imo",
          "vessel_name"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own unique id for this record."
          },
          "imo": {
            "type": "string",
            "maxLength": 120,
            "description": "IMO number (7 digits, check digit validated)."
          },
          "vessel_name": {
            "type": "string",
            "maxLength": 120,
            "description": "Vessel name."
          },
          "call_ref": {
            "type": "string",
            "maxLength": 120,
            "description": "Your port-call reference."
          },
          "voyage_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Voyage number."
          },
          "berth": {
            "type": "string",
            "maxLength": 120,
            "description": "Berth code."
          },
          "lot_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Cargo lot discharged or loaded."
          },
          "eta_at": {
            "type": "string",
            "format": "date-time",
            "description": "Estimated arrival."
          },
          "ata_at": {
            "type": "string",
            "format": "date-time",
            "description": "Actual arrival."
          },
          "nor_tendered_at": {
            "type": "string",
            "format": "date-time",
            "description": "Notice of readiness tendered."
          },
          "all_fast_at": {
            "type": "string",
            "format": "date-time",
            "description": "All fast."
          },
          "discharge_completed_at": {
            "type": "string",
            "format": "date-time",
            "description": "Discharge completed."
          },
          "loading_completed_at": {
            "type": "string",
            "format": "date-time",
            "description": "Loading completed."
          },
          "planned_sailing_at": {
            "type": "string",
            "format": "date-time",
            "description": "Planned sailing."
          },
          "sailing_at": {
            "type": "string",
            "format": "date-time",
            "description": "Actual sailing."
          }
        },
        "additionalProperties": false,
        "example": {
          "external_id": "CALL-2026-0921",
          "imo": "9074729",
          "vessel_name": "MV EXAMPLE",
          "call_ref": "KLP-2026-0921-VC07",
          "ata_at": "2026-10-08T04:20:00+03:00"
        }
      },
      "Record_stock_movement": {
        "type": "object",
        "title": "Stock movement",
        "description": "One receipt into or issue out of stock for a cargo lot. At least one of: receipt_t, issue_t, receipt_kg, issue_kg.",
        "required": [
          "external_id",
          "lot_code",
          "moved_at"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own unique id for this record."
          },
          "lot_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Cargo lot."
          },
          "moved_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the movement happened."
          },
          "receipt_t": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Received, tonnes."
          },
          "issue_t": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Issued, tonnes."
          },
          "receipt_kg": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Received, kilograms."
          },
          "issue_kg": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Issued, kilograms."
          },
          "location_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Storage location."
          },
          "reason": {
            "type": "string",
            "maxLength": 300,
            "description": "Reason or document reference."
          }
        },
        "additionalProperties": false,
        "example": {
          "external_id": "STK-2026-10-08-0007",
          "lot_code": "LOT-WHEAT-0007",
          "moved_at": "2026-10-08T09:00:00+03:00",
          "issue_t": "25.94",
          "location_code": "SILO-3"
        }
      },
      "Record_invoice_line": {
        "type": "object",
        "title": "Invoice line",
        "description": "One line of an issued invoice, already billed.",
        "required": [
          "external_id",
          "service_code",
          "amount",
          "invoice_date"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own unique id for this record."
          },
          "service_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Service code of the line (e.g. storage, handling)."
          },
          "amount": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Line amount."
          },
          "invoice_date": {
            "type": "string",
            "format": "date",
            "description": "Invoice date (YYYY-MM-DD)."
          },
          "invoice_ref": {
            "type": "string",
            "maxLength": 120,
            "description": "Invoice number."
          },
          "quantity": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Quantity billed."
          },
          "unit": {
            "type": "string",
            "maxLength": 120,
            "description": "Unit of the quantity."
          },
          "rate": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Rate per unit."
          },
          "currency": {
            "type": "string",
            "maxLength": 3,
            "description": "ISO 4217 currency code (default EUR)."
          },
          "reference": {
            "type": "string",
            "maxLength": 120,
            "description": "Vessel call, wagon or booking the line bills for."
          },
          "lot_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Cargo lot."
          },
          "payer_code": {
            "type": "string",
            "maxLength": 120,
            "description": "Payer party code."
          }
        },
        "additionalProperties": false,
        "example": {
          "external_id": "INV-2026-0451-L2",
          "service_code": "storage",
          "amount": "1840.50",
          "invoice_date": "2026-10-08",
          "invoice_ref": "INV-2026-0451",
          "currency": "EUR",
          "reference": "KLP-2026-0921-VC07"
        }
      },
      "Record_carrier_statement_line": {
        "type": "object",
        "title": "Carrier statement line",
        "description": "One line of a railway carrier's wagon-use or storage statement.",
        "required": [
          "external_id",
          "wagon_no",
          "service_code"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own unique id for this record."
          },
          "wagon_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Wagon number (12-digit UIC or 8-digit 1520)."
          },
          "service_code": {
            "type": "string",
            "maxLength": 120,
            "description": "wagon-use or storage-organisation."
          },
          "billed_qty": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Hours or days billed."
          },
          "rate_eur": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Rate in EUR."
          },
          "amount_eur": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Line amount in EUR."
          },
          "period_start": {
            "type": "string",
            "format": "date",
            "description": "Start of the billed period."
          },
          "period_end": {
            "type": "string",
            "format": "date",
            "description": "End of the billed period."
          },
          "invoice_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Statement or invoice number."
          },
          "line_no": {
            "type": "string",
            "maxLength": 120,
            "description": "Line number on the statement."
          },
          "station": {
            "type": "string",
            "maxLength": 120,
            "description": "Station."
          }
        },
        "additionalProperties": false,
        "example": {
          "external_id": "LTG-2026-10-L0001",
          "wagon_no": "315600270120",
          "service_code": "wagon-use",
          "billed_qty": "36",
          "rate_eur": "1.15",
          "amount_eur": "41.40"
        }
      },
      "RecordsRequest": {
        "type": "object",
        "required": [
          "record_type",
          "records"
        ],
        "properties": {
          "record_type": {
            "type": "string",
            "enum": [
              "weighbridge_ticket",
              "wagon_visit",
              "truck_visit",
              "vessel_call",
              "stock_movement",
              "invoice_line",
              "carrier_statement_line"
            ]
          },
          "records": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/Record_weighbridge_ticket"
                },
                {
                  "$ref": "#/components/schemas/Record_wagon_visit"
                },
                {
                  "$ref": "#/components/schemas/Record_truck_visit"
                },
                {
                  "$ref": "#/components/schemas/Record_vessel_call"
                },
                {
                  "$ref": "#/components/schemas/Record_stock_movement"
                },
                {
                  "$ref": "#/components/schemas/Record_invoice_line"
                },
                {
                  "$ref": "#/components/schemas/Record_carrier_statement_line"
                }
              ]
            },
            "description": "All records must be of the type named in record_type."
          },
          "correction_reason": {
            "type": "string",
            "minLength": 3,
            "maxLength": 300,
            "description": "Set this to send a corrected version of records you sent before; the earlier version is kept and superseded, never overwritten."
          }
        },
        "additionalProperties": false
      },
      "WebhookEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "api_version",
          "created_at",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Stable per event; the same on retries and replays."
          },
          "type": {
            "type": "string",
            "enum": [
              "finding.created",
              "webhook.test"
            ]
          },
          "api_version": {
            "type": "string",
            "example": "v1"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "$ref": "#/components/schemas/PublicFinding"
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "description": "Authorization: Bearer otk_...",
        "scheme": "bearer"
      }
    }
  },
  "webhooks": {
    "findingCreated": {
      "post": {
        "summary": "A new finding was detected",
        "description": "Sent to each webhook endpoint you configured. Verify the `Outturn-Signature` header: `t=<unix seconds>,v1=<hex>` where v1 is HMAC-SHA256 of `<t>.` + the raw body with your signing secret. Reject a `t` older than 5 minutes. Respond with any 2xx to acknowledge; other answers are retried after 1 min, 5 min, 30 min, 2 h, 6 h, 12 h and 24 h. De-duplicate on the envelope `id`.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged."
          }
        }
      }
    }
  }
}
