{
  "openapi": "3.1.0",
  "info": {
    "title": "Walnut Labs API reference",
    "version": "1.0.0",
    "description": "All custom Production Record Data API operations. Capture endpoints are published over HTTPS; engineering endpoints require internal network access. HTTP Basic credentials are issued by the system owner. This page is a read-only reference with fictional examples; it stores no credentials and makes no API requests. ERPNext and Dagster are separate products, not part of this API contract."
  },
  "servers": [
    {
      "url": "https://api.walnutserver.com",
      "description": "Public capture API; HTTPS and Basic authentication"
    }
  ],
  "tags": [
    {
      "name": "Production record capture",
      "description": "Public integration contract. Check API Message and pass/fail fields even when HTTP status is 200."
    },
    {
      "name": "Engineering · internal network",
      "description": "LAN-only diagnostics and data with lineage. Not routed by the public API edge."
    }
  ],
  "paths": {
    "/api/check": {
      "get": {
        "tags": [
          "Production record capture"
        ],
        "summary": "Check the connection",
        "description": "Unauthenticated connection probe. Does not verify credentials, warehouse connectivity or freshness.",
        "operationId": "get_api_check",
        "servers": [
          {
            "url": "https://api.walnutserver.com",
            "description": "Public capture API; HTTPS and Basic authentication"
          }
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The literal two characters {} as text/plain.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "example": "{}"
              }
            }
          }
        }
      },
      "head": {
        "tags": [
          "Production record capture"
        ],
        "summary": "Check connection headers",
        "description": "Unauthenticated connection probe. Does not verify credentials, warehouse connectivity or freshness.",
        "operationId": "head_api_check",
        "servers": [
          {
            "url": "https://api.walnutserver.com",
            "description": "Public capture API; HTTPS and Basic authentication"
          }
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Connection accepted; no body for HEAD."
          }
        }
      }
    },
    "/api/material_verify": {
      "get": {
        "tags": [
          "Production record capture"
        ],
        "summary": "Verify a scanned material batch",
        "description": "Returns a flat row for a lot-context request. OK and EXPIRING_SOON pass the expiry check; EXPIRED and UNDATED fail. Missing inputs, an unknown batch or a warehouse lookup failure return HTTP 200 with a failure message and expiry flag 0. Stale pipeline data adds a warning to API Message; it does not change the expiry flag. Work Order is accepted but currently unused. Without a nonblank currentLotNumber, returns a one-row discovery page. All row values are strings capped at 2,000 characters. Input labels are matched ignoring case and punctuation; use the canonical labels below.",
        "operationId": "get_api_material_verify",
        "servers": [
          {
            "url": "https://api.walnutserver.com",
            "description": "Public capture API; HTTPS and Basic authentication"
          }
        ],
        "security": [
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/MaterialRow"
                    },
                    {
                      "$ref": "#/components/schemas/MaterialPage"
                    }
                  ]
                },
                "examples": {
                  "success": {
                    "summary": "Illustrative response; identifiers are fictional",
                    "value": {
                      "Material Scan": "DEMO-BATCH-001",
                      "Batch Number": "DEMO-BATCH-001",
                      "Item Code": "DEMO-RAW-001",
                      "Description": "Example material",
                      "Manufacturing Date": "2026-01-01",
                      "Expiration Date": "2027-01-01",
                      "Batch Status": "OK",
                      "Expiry Check (Pass=1, Fail=0)": "1",
                      "API Message": "OK."
                    }
                  },
                  "discovery": {
                    "summary": "No currentLotNumber: discover field labels (dates vary)",
                    "value": {
                      "empty": false,
                      "numberOfElements": 1,
                      "size": 1,
                      "totalElements": 1,
                      "first": true,
                      "number": 0,
                      "totalPages": 1,
                      "last": true,
                      "content": [
                        {
                          "Material Scan": "test",
                          "Batch Number": "test",
                          "Item Code": "test",
                          "Description": "test",
                          "Manufacturing Date": "2026-09-20",
                          "Expiration Date": "2026-09-20",
                          "Batch Status": "test",
                          "Expiry Check (Pass=1, Fail=0)": "1",
                          "API Message": "test"
                        }
                      ],
                      "sort": {
                        "empty": false,
                        "unsorted": true,
                        "sorted": false
                      },
                      "pageable": {
                        "offset": 0,
                        "pageNumber": 0,
                        "pageSize": 1,
                        "paged": false,
                        "unpaged": true
                      }
                    }
                  },
                  "missingInput": {
                    "summary": "Lot context present but required input missing; HTTP 200",
                    "value": {
                      "Material Scan": "",
                      "Batch Number": "",
                      "Item Code": "",
                      "Description": "",
                      "Manufacturing Date": "",
                      "Expiration Date": "",
                      "Batch Status": "",
                      "Expiry Check (Pass=1, Fail=0)": "0",
                      "API Message": "No material scanned. Scan the container label, or enter the batch number manually."
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "400": {
            "description": "Bad Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "401": {
            "description": "Missing or non-Basic Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "schema": {
                  "type": "string"
                },
                "description": "Basic authentication challenge."
              },
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "403": {
            "description": "Unknown client or incorrect secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          }
        },
        "parameters": [
          {
            "name": "currentLotNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Nonblank value selects live lookup mode; omit for field discovery. This is a mode indicator, not a batch filter.",
            "example": "DEMO-LOT-001"
          },
          {
            "name": "Material Scan",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for a useful lookup when currentLotNumber is supplied. URL-encode spaces in parameter names.",
            "example": "DEMO-BATCH-001"
          },
          {
            "name": "Work Order",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Accepted but unused on this endpoint.",
            "example": "DEMO-WO-001"
          }
        ]
      }
    },
    "/api/work_order_header": {
      "get": {
        "tags": [
          "Production record capture"
        ],
        "summary": "Read a work order header",
        "description": "Returns a flat row for a lot-context request. Missing inputs, an unknown work order or a warehouse lookup failure return HTTP 200 with API Message explaining the problem. This endpoint does not apply a freshness gate. Without a nonblank currentLotNumber, returns a one-row discovery page. All row values are strings capped at 2,000 characters. Input labels are matched ignoring case and punctuation; use the canonical labels below.",
        "operationId": "get_api_work_order_header",
        "servers": [
          {
            "url": "https://api.walnutserver.com",
            "description": "Public capture API; HTTPS and Basic authentication"
          }
        ],
        "security": [
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/WorkOrderRow"
                    },
                    {
                      "$ref": "#/components/schemas/WorkOrderPage"
                    }
                  ]
                },
                "examples": {
                  "success": {
                    "summary": "Illustrative response; identifiers are fictional",
                    "value": {
                      "Work Order": "DEMO-WO-001",
                      "Product Code": "DEMO-FG-001",
                      "Product Description": "Example product",
                      "Planned Quantity": "100.0",
                      "Unit of Measure": "Nos",
                      "BOM": "DEMO-BOM-001",
                      "Status": "In Process",
                      "Planned Start Date": "2026-09-19",
                      "API Message": "OK."
                    }
                  },
                  "discovery": {
                    "summary": "No currentLotNumber: discover field labels (dates vary)",
                    "value": {
                      "empty": false,
                      "numberOfElements": 1,
                      "size": 1,
                      "totalElements": 1,
                      "first": true,
                      "number": 0,
                      "totalPages": 1,
                      "last": true,
                      "content": [
                        {
                          "Work Order": "test",
                          "Product Code": "test",
                          "Product Description": "test",
                          "Planned Quantity": "test",
                          "Unit of Measure": "test",
                          "BOM": "test",
                          "Status": "test",
                          "Planned Start Date": "2026-09-20",
                          "API Message": "test"
                        }
                      ],
                      "sort": {
                        "empty": false,
                        "unsorted": true,
                        "sorted": false
                      },
                      "pageable": {
                        "offset": 0,
                        "pageNumber": 0,
                        "pageSize": 1,
                        "paged": false,
                        "unpaged": true
                      }
                    }
                  },
                  "missingInput": {
                    "summary": "Lot context present but required input missing; HTTP 200",
                    "value": {
                      "Work Order": "",
                      "Product Code": "",
                      "Product Description": "",
                      "Planned Quantity": "",
                      "Unit of Measure": "",
                      "BOM": "",
                      "Status": "",
                      "Planned Start Date": "",
                      "API Message": "No work order supplied."
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "400": {
            "description": "Bad Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "401": {
            "description": "Missing or non-Basic Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "schema": {
                  "type": "string"
                },
                "description": "Basic authentication challenge."
              },
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "403": {
            "description": "Unknown client or incorrect secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          }
        },
        "parameters": [
          {
            "name": "currentLotNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Nonblank value selects live lookup mode; omit for field discovery. This is a mode indicator, not a batch filter.",
            "example": "DEMO-LOT-001"
          },
          {
            "name": "Work Order",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for a useful lookup when currentLotNumber is supplied. URL-encode spaces in parameter names.",
            "example": "DEMO-WO-001"
          }
        ]
      }
    },
    "/api/material_list": {
      "get": {
        "tags": [
          "Production record capture"
        ],
        "summary": "List materials issued to a work order",
        "description": "Always returns a paged envelope with rows in content, including live requests. No issued materials, missing inputs or a warehouse lookup failure return one blank row with API Message, HTTP 200. Despite its label, Expired Before Issue (Pass=1, Fail=0) is 1 when NOT expired at issue and 0 when expired. This endpoint does not apply a freshness gate. Without a nonblank currentLotNumber, returns a one-row discovery page. All row values are strings capped at 2,000 characters. Input labels are matched ignoring case and punctuation; use the canonical labels below.",
        "operationId": "get_api_material_list",
        "servers": [
          {
            "url": "https://api.walnutserver.com",
            "description": "Public capture API; HTTPS and Basic authentication"
          }
        ],
        "security": [
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConsumptionPage"
                },
                "examples": {
                  "success": {
                    "summary": "Illustrative response; identifiers are fictional",
                    "value": {
                      "empty": false,
                      "numberOfElements": 1,
                      "size": 1,
                      "totalElements": 1,
                      "first": true,
                      "number": 0,
                      "totalPages": 1,
                      "last": true,
                      "content": [
                        {
                          "Work Order": "DEMO-WO-001",
                          "Item Code": "DEMO-RAW-001",
                          "Description": "Example material",
                          "Batch Number": "DEMO-BATCH-001",
                          "Manufacturing Date": "2026-01-01",
                          "Expiration Date": "2027-01-01",
                          "Issued Quantity": "10.0",
                          "Unit of Measure": "Kg",
                          "Expired Before Issue (Pass=1, Fail=0)": "1",
                          "API Message": "OK."
                        }
                      ],
                      "sort": {
                        "empty": false,
                        "unsorted": true,
                        "sorted": false
                      },
                      "pageable": {
                        "offset": 0,
                        "pageNumber": 0,
                        "pageSize": 1,
                        "paged": false,
                        "unpaged": true
                      }
                    }
                  },
                  "discovery": {
                    "summary": "No currentLotNumber: discover field labels (dates vary)",
                    "value": {
                      "empty": false,
                      "numberOfElements": 1,
                      "size": 1,
                      "totalElements": 1,
                      "first": true,
                      "number": 0,
                      "totalPages": 1,
                      "last": true,
                      "content": [
                        {
                          "Work Order": "test",
                          "Item Code": "test",
                          "Description": "test",
                          "Batch Number": "test",
                          "Manufacturing Date": "2026-09-20",
                          "Expiration Date": "2026-09-20",
                          "Issued Quantity": "test",
                          "Unit of Measure": "test",
                          "Expired Before Issue (Pass=1, Fail=0)": "1",
                          "API Message": "test"
                        }
                      ],
                      "sort": {
                        "empty": false,
                        "unsorted": true,
                        "sorted": false
                      },
                      "pageable": {
                        "offset": 0,
                        "pageNumber": 0,
                        "pageSize": 1,
                        "paged": false,
                        "unpaged": true
                      }
                    }
                  },
                  "missingInput": {
                    "summary": "Lot context present but required input missing; HTTP 200",
                    "value": {
                      "empty": false,
                      "numberOfElements": 1,
                      "size": 1,
                      "totalElements": 1,
                      "first": true,
                      "number": 0,
                      "totalPages": 1,
                      "last": true,
                      "content": [
                        {
                          "Work Order": "",
                          "Item Code": "",
                          "Description": "",
                          "Batch Number": "",
                          "Manufacturing Date": "",
                          "Expiration Date": "",
                          "Issued Quantity": "",
                          "Unit of Measure": "",
                          "Expired Before Issue (Pass=1, Fail=0)": "",
                          "API Message": "No work order supplied."
                        }
                      ],
                      "sort": {
                        "empty": false,
                        "unsorted": true,
                        "sorted": false
                      },
                      "pageable": {
                        "offset": 0,
                        "pageNumber": 0,
                        "pageSize": 1,
                        "paged": false,
                        "unpaged": true
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "400": {
            "description": "Bad Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "401": {
            "description": "Missing or non-Basic Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "schema": {
                  "type": "string"
                },
                "description": "Basic authentication challenge."
              },
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "403": {
            "description": "Unknown client or incorrect secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          }
        },
        "parameters": [
          {
            "name": "currentLotNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Nonblank value selects live lookup mode; omit for field discovery. This is a mode indicator, not a batch filter.",
            "example": "DEMO-LOT-001"
          },
          {
            "name": "Work Order",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for a useful lookup when currentLotNumber is supplied. URL-encode spaces in parameter names.",
            "example": "DEMO-WO-001"
          }
        ]
      }
    },
    "/v1/work-orders/{work_order}": {
      "get": {
        "tags": [
          "Engineering · internal network"
        ],
        "summary": "Read a work order with lineage",
        "description": "Internal network only; the public edge returns 404 for /v1/*. Requires Basic authentication. Returns curated rows and lineage metadata. Unknown record: 404. Pipeline past its freshness SLA: 503. Unhandled warehouse failures may return 500. A missing record never returns an empty success.",
        "operationId": "get_v1_work_orders_work_order",
        "servers": [
          {
            "url": "/",
            "description": "Internal API origin only — replace with your approved LAN origin; not the website or public API host"
          }
        ],
        "security": [
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                },
                "examples": {
                  "success": {
                    "summary": "Illustrative subset of mart columns; not live data",
                    "value": {
                      "data": [
                        {
                          "work_order": "DEMO-WO-001",
                          "item_code": "DEMO-FG-001",
                          "planned_qty": 100,
                          "stock_uom": "Nos"
                        }
                      ],
                      "meta": {
                        "request_id": null,
                        "api_version": "1.0.0",
                        "source_system": "ERPNext",
                        "data_as_of": "2026-09-19T12:00:00+00:00",
                        "iceberg_snapshot_id": 123456789,
                        "dlt_load_id": "demo-load-001",
                        "stale": false,
                        "warnings": []
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "400": {
            "description": "Bad Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "401": {
            "description": "Missing or non-Basic Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "schema": {
                  "type": "string"
                },
                "description": "Basic authentication challenge."
              },
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "403": {
            "description": "Unknown client or incorrect secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "404": {
            "description": "Record not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Stale pipeline data; use manual fallback",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StaleData"
                }
              }
            }
          },
          "500": {
            "description": "Unhandled warehouse or snapshot lookup error."
          }
        },
        "parameters": [
          {
            "name": "work_order",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "DEMO-WO-001"
          }
        ]
      }
    },
    "/v1/work-orders/{work_order}/materials": {
      "get": {
        "tags": [
          "Engineering · internal network"
        ],
        "summary": "Read issued materials with lineage",
        "description": "Internal network only; the public edge returns 404 for /v1/*. Requires Basic authentication. Returns curated rows and lineage metadata. Unknown record: 404. Pipeline past its freshness SLA: 503. Unhandled warehouse failures may return 500. A known work order with no issued materials returns an empty data list; expired materials add warnings.",
        "operationId": "get_v1_work_orders_work_order_materials",
        "servers": [
          {
            "url": "/",
            "description": "Internal API origin only — replace with your approved LAN origin; not the website or public API host"
          }
        ],
        "security": [
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                },
                "examples": {
                  "success": {
                    "summary": "Illustrative subset of mart columns; not live data",
                    "value": {
                      "data": [
                        {
                          "work_order": "DEMO-WO-001",
                          "item_code": "DEMO-RAW-001",
                          "batch_no": "DEMO-BATCH-001",
                          "issued_qty": 10,
                          "is_expired_at_issue": false
                        }
                      ],
                      "meta": {
                        "request_id": null,
                        "api_version": "1.0.0",
                        "source_system": "ERPNext",
                        "data_as_of": "2026-09-19T12:00:00+00:00",
                        "iceberg_snapshot_id": 123456789,
                        "dlt_load_id": "demo-load-001",
                        "stale": false,
                        "warnings": []
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "400": {
            "description": "Bad Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "401": {
            "description": "Missing or non-Basic Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "schema": {
                  "type": "string"
                },
                "description": "Basic authentication challenge."
              },
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "403": {
            "description": "Unknown client or incorrect secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "404": {
            "description": "Record not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Stale pipeline data; use manual fallback",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StaleData"
                }
              }
            }
          },
          "500": {
            "description": "Unhandled warehouse or snapshot lookup error."
          }
        },
        "parameters": [
          {
            "name": "work_order",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "DEMO-WO-001"
          }
        ]
      }
    },
    "/v1/batches/{batch_no}": {
      "get": {
        "tags": [
          "Engineering · internal network"
        ],
        "summary": "Read a batch with lineage",
        "description": "Internal network only; the public edge returns 404 for /v1/*. Requires Basic authentication. Returns curated rows and lineage metadata. Unknown record: 404. Pipeline past its freshness SLA: 503. Unhandled warehouse failures may return 500. A missing record never returns an empty success.",
        "operationId": "get_v1_batches_batch_no",
        "servers": [
          {
            "url": "/",
            "description": "Internal API origin only — replace with your approved LAN origin; not the website or public API host"
          }
        ],
        "security": [
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                },
                "examples": {
                  "success": {
                    "summary": "Illustrative subset of mart columns; not live data",
                    "value": {
                      "data": [
                        {
                          "batch_no": "DEMO-BATCH-001",
                          "item_code": "DEMO-RAW-001",
                          "batch_status": "OK",
                          "expiry_date": "2027-01-01"
                        }
                      ],
                      "meta": {
                        "request_id": null,
                        "api_version": "1.0.0",
                        "source_system": "ERPNext",
                        "data_as_of": "2026-09-19T12:00:00+00:00",
                        "iceberg_snapshot_id": 123456789,
                        "dlt_load_id": "demo-load-001",
                        "stale": false,
                        "warnings": []
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "400": {
            "description": "Bad Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "401": {
            "description": "Missing or non-Basic Authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "WWW-Authenticate": {
                "schema": {
                  "type": "string"
                },
                "description": "Basic authentication challenge."
              },
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "403": {
            "description": "Unknown client or incorrect secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "404": {
            "description": "Record not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Stale pipeline data; use manual fallback",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StaleData"
                }
              }
            }
          },
          "500": {
            "description": "Unhandled warehouse or snapshot lookup error."
          }
        },
        "parameters": [
          {
            "name": "batch_no",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "DEMO-BATCH-001"
          }
        ]
      }
    },
    "/v1/health": {
      "get": {
        "tags": [
          "Engineering · internal network"
        ],
        "summary": "Check warehouse connectivity",
        "description": "Internal network only. No authentication. Pings Trino; does not assert pipeline freshness.",
        "operationId": "get_v1_health",
        "servers": [
          {
            "url": "/",
            "description": "Internal API origin only — replace with your approved LAN origin; not the website or public API host"
          }
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "examples": {
                  "healthy": {
                    "value": {
                      "status": "ok",
                      "trino_reachable": true,
                      "api_version": "1.0.0"
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "503": {
            "description": "Warehouse unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "degraded",
                  "trino_reachable": false,
                  "api_version": "1.0.0"
                }
              }
            }
          }
        }
      }
    },
    "/v1/freshness": {
      "get": {
        "tags": [
          "Engineering · internal network"
        ],
        "summary": "Inspect pipeline freshness",
        "description": "Internal network only. No authentication. Measures age of the pipeline rebuild, not source activity. Default warning/SLA thresholds are 15/60 minutes; deployment settings can override them. Missing or unreadable heartbeat also marks the data stale.",
        "operationId": "get_v1_freshness",
        "servers": [
          {
            "url": "/",
            "description": "Internal API origin only — replace with your approved LAN origin; not the website or public API host"
          }
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Freshness"
                },
                "examples": {
                  "fresh": {
                    "value": {
                      "built_at": "2026-09-19T12:00:00+00:00",
                      "data_as_of": "2026-09-19T12:00:00+00:00",
                      "source_modified_at": "2026-09-18T08:00:00+00:00",
                      "age_minutes": 5,
                      "stale": false,
                      "warn": false,
                      "sla_minutes": 60,
                      "warn_minutes": 15,
                      "dlt_load_id": "demo-load-001",
                      "error": null
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID."
              }
            }
          },
          "503": {
            "description": "Pipeline stale or heartbeat unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Freshness"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "basicAuth": {
        "type": "http",
        "scheme": "basic",
        "description": "Provisioned client ID and secret; use HTTPS on the public host. Never put credentials in URLs."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "detail": {
            "type": "string"
          }
        },
        "required": [
          "detail"
        ]
      },
      "Meta": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Currently null; use the X-Request-ID response header for correlation."
          },
          "api_version": {
            "type": "string"
          },
          "source_system": {
            "type": "string"
          },
          "data_as_of": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Pipeline rebuild time, not newest source document time."
          },
          "iceberg_snapshot_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Snapshot identifier for replay."
          },
          "dlt_load_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "stale": {
            "type": "boolean"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "request_id",
          "api_version",
          "source_system",
          "data_as_of",
          "iceberg_snapshot_id",
          "dlt_load_id",
          "stale",
          "warnings"
        ]
      },
      "Envelope": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            },
            "description": "Rows from the curated mart. Columns follow the current warehouse schema."
          },
          "meta": {
            "$ref": "#/components/schemas/Meta"
          }
        },
        "required": [
          "data",
          "meta"
        ]
      },
      "Health": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded"
            ]
          },
          "trino_reachable": {
            "type": "boolean"
          },
          "api_version": {
            "type": "string"
          }
        },
        "required": [
          "status",
          "trino_reachable",
          "api_version"
        ]
      },
      "Freshness": {
        "type": "object",
        "properties": {
          "built_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "data_as_of": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Alias of built_at."
          },
          "source_modified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Source activity, informational only; does not gate the SLA."
          },
          "age_minutes": {
            "type": [
              "number",
              "null"
            ]
          },
          "stale": {
            "type": "boolean"
          },
          "warn": {
            "type": "boolean"
          },
          "sla_minutes": {
            "type": "integer"
          },
          "warn_minutes": {
            "type": "integer"
          },
          "dlt_load_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "built_at",
          "data_as_of",
          "source_modified_at",
          "age_minutes",
          "stale",
          "warn",
          "sla_minutes",
          "warn_minutes",
          "dlt_load_id",
          "error"
        ]
      },
      "StaleData": {
        "type": "object",
        "properties": {
          "detail": {
            "type": "object",
            "properties": {
              "error": {
                "const": "stale_data"
              },
              "message": {
                "type": "string"
              },
              "meta": {
                "$ref": "#/components/schemas/Meta"
              }
            },
            "required": [
              "error",
              "message",
              "meta"
            ]
          }
        },
        "required": [
          "detail"
        ]
      },
      "MaterialRow": {
        "type": "object",
        "properties": {
          "Material Scan": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Batch Number": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Item Code": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Description": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Manufacturing Date": {
            "type": "string",
            "maxLength": 2000,
            "description": "YYYY-MM-DD or empty when unavailable."
          },
          "Expiration Date": {
            "type": "string",
            "maxLength": 2000,
            "description": "YYYY-MM-DD or empty when unavailable."
          },
          "Batch Status": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Expiry Check (Pass=1, Fail=0)": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable.",
            "enum": [
              "",
              "0",
              "1"
            ]
          },
          "API Message": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          }
        },
        "required": [
          "Material Scan",
          "Batch Number",
          "Item Code",
          "Description",
          "Manufacturing Date",
          "Expiration Date",
          "Batch Status",
          "Expiry Check (Pass=1, Fail=0)",
          "API Message"
        ],
        "additionalProperties": false
      },
      "MaterialPage": {
        "type": "object",
        "properties": {
          "empty": {
            "type": "boolean"
          },
          "numberOfElements": {
            "type": "integer"
          },
          "size": {
            "type": "integer"
          },
          "totalElements": {
            "type": "integer"
          },
          "first": {
            "type": "boolean"
          },
          "number": {
            "type": "integer"
          },
          "totalPages": {
            "type": "integer"
          },
          "last": {
            "type": "boolean"
          },
          "content": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MaterialRow"
            }
          },
          "sort": {
            "type": "object",
            "properties": {
              "empty": {
                "type": "boolean"
              },
              "unsorted": {
                "type": "boolean"
              },
              "sorted": {
                "type": "boolean"
              }
            },
            "required": [
              "empty",
              "unsorted",
              "sorted"
            ]
          },
          "pageable": {
            "type": "object",
            "properties": {
              "offset": {
                "type": "integer"
              },
              "pageNumber": {
                "type": "integer"
              },
              "pageSize": {
                "type": "integer"
              },
              "paged": {
                "type": "boolean"
              },
              "unpaged": {
                "type": "boolean"
              }
            },
            "required": [
              "offset",
              "pageNumber",
              "pageSize",
              "paged",
              "unpaged"
            ]
          }
        },
        "required": [
          "empty",
          "numberOfElements",
          "size",
          "totalElements",
          "first",
          "number",
          "totalPages",
          "last",
          "content",
          "sort",
          "pageable"
        ]
      },
      "WorkOrderRow": {
        "type": "object",
        "properties": {
          "Work Order": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Product Code": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Product Description": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Planned Quantity": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Unit of Measure": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "BOM": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Status": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Planned Start Date": {
            "type": "string",
            "maxLength": 2000,
            "description": "YYYY-MM-DD or empty when unavailable."
          },
          "API Message": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          }
        },
        "required": [
          "Work Order",
          "Product Code",
          "Product Description",
          "Planned Quantity",
          "Unit of Measure",
          "BOM",
          "Status",
          "Planned Start Date",
          "API Message"
        ],
        "additionalProperties": false
      },
      "WorkOrderPage": {
        "type": "object",
        "properties": {
          "empty": {
            "type": "boolean"
          },
          "numberOfElements": {
            "type": "integer"
          },
          "size": {
            "type": "integer"
          },
          "totalElements": {
            "type": "integer"
          },
          "first": {
            "type": "boolean"
          },
          "number": {
            "type": "integer"
          },
          "totalPages": {
            "type": "integer"
          },
          "last": {
            "type": "boolean"
          },
          "content": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkOrderRow"
            }
          },
          "sort": {
            "type": "object",
            "properties": {
              "empty": {
                "type": "boolean"
              },
              "unsorted": {
                "type": "boolean"
              },
              "sorted": {
                "type": "boolean"
              }
            },
            "required": [
              "empty",
              "unsorted",
              "sorted"
            ]
          },
          "pageable": {
            "type": "object",
            "properties": {
              "offset": {
                "type": "integer"
              },
              "pageNumber": {
                "type": "integer"
              },
              "pageSize": {
                "type": "integer"
              },
              "paged": {
                "type": "boolean"
              },
              "unpaged": {
                "type": "boolean"
              }
            },
            "required": [
              "offset",
              "pageNumber",
              "pageSize",
              "paged",
              "unpaged"
            ]
          }
        },
        "required": [
          "empty",
          "numberOfElements",
          "size",
          "totalElements",
          "first",
          "number",
          "totalPages",
          "last",
          "content",
          "sort",
          "pageable"
        ]
      },
      "ConsumptionRow": {
        "type": "object",
        "properties": {
          "Work Order": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Item Code": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Description": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Batch Number": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Manufacturing Date": {
            "type": "string",
            "maxLength": 2000,
            "description": "YYYY-MM-DD or empty when unavailable."
          },
          "Expiration Date": {
            "type": "string",
            "maxLength": 2000,
            "description": "YYYY-MM-DD or empty when unavailable."
          },
          "Issued Quantity": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Unit of Measure": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          },
          "Expired Before Issue (Pass=1, Fail=0)": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable.",
            "enum": [
              "",
              "0",
              "1"
            ]
          },
          "API Message": {
            "type": "string",
            "maxLength": 2000,
            "description": "String value; may be empty when unavailable."
          }
        },
        "required": [
          "Work Order",
          "Item Code",
          "Description",
          "Batch Number",
          "Manufacturing Date",
          "Expiration Date",
          "Issued Quantity",
          "Unit of Measure",
          "Expired Before Issue (Pass=1, Fail=0)",
          "API Message"
        ],
        "additionalProperties": false
      },
      "ConsumptionPage": {
        "type": "object",
        "properties": {
          "empty": {
            "type": "boolean"
          },
          "numberOfElements": {
            "type": "integer"
          },
          "size": {
            "type": "integer"
          },
          "totalElements": {
            "type": "integer"
          },
          "first": {
            "type": "boolean"
          },
          "number": {
            "type": "integer"
          },
          "totalPages": {
            "type": "integer"
          },
          "last": {
            "type": "boolean"
          },
          "content": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ConsumptionRow"
            }
          },
          "sort": {
            "type": "object",
            "properties": {
              "empty": {
                "type": "boolean"
              },
              "unsorted": {
                "type": "boolean"
              },
              "sorted": {
                "type": "boolean"
              }
            },
            "required": [
              "empty",
              "unsorted",
              "sorted"
            ]
          },
          "pageable": {
            "type": "object",
            "properties": {
              "offset": {
                "type": "integer"
              },
              "pageNumber": {
                "type": "integer"
              },
              "pageSize": {
                "type": "integer"
              },
              "paged": {
                "type": "boolean"
              },
              "unpaged": {
                "type": "boolean"
              }
            },
            "required": [
              "offset",
              "pageNumber",
              "pageSize",
              "paged",
              "unpaged"
            ]
          }
        },
        "required": [
          "empty",
          "numberOfElements",
          "size",
          "totalElements",
          "first",
          "number",
          "totalPages",
          "last",
          "content",
          "sort",
          "pageable"
        ]
      }
    }
  }
}
