{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/smartroutes-io/json-schema/smartroutes-io-orders-list-response-schema.json",
  "title": "OrdersListResponse",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/smartroutes-io-openapi.json#/components/schemas/OrdersListResponse",
  "type": "object",
  "required": [
    "orders"
  ],
  "properties": {
    "orders": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/OrderListItem"
      }
    }
  },
  "$defs": {
    "Capacity": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "type": {
          "type": "string"
        },
        "capacity": {
          "type": [
            "number",
            "null"
          ]
        }
      }
    },
    "CustomField": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "value": {
          "description": "Field value. Type varies by field definition (string, number, or boolean)."
        }
      }
    },
    "Customer": {
      "type": [
        "object",
        "null"
      ],
      "description": "Trimmed customer reference embedded in Order responses. May be `null` for orders without a customer association.",
      "properties": {
        "id": {
          "type": [
            "integer",
            "null"
          ]
        },
        "account": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "DriverQuestionnaireSubmission": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "order_id": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Set only on `VISIT_ORDER` submissions: the order at the stop this submission is about. `null` for `ROUTE_VEHICLE_CHECKIN` and `VISIT` submissions. Under an order's `stops`, only that order's submissions and the stop's own (`order_id: null`) are listed. An order's own submissions, with their answers, are also in `driver_questionnaire_submissions` on `GET /orders/{id}`."
        },
        "order_line_item_id": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Set only on `VISIT_ORDER` submissions about a single line item of `order_id` — matches `LineItem.id`. `null` when the submission is about the whole order."
        },
        "driver_questionnaire": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "description": "What the questionnaire is attached to. One of `ROUTE_VEHICLE_CHECKIN` (the route), `VISIT` (a stop), or `VISIT_ORDER` (one order, or one line item of an order, at a stop — see `order_id` and `order_line_item_id`). New values may be added; treat unknown values as opaque."
            },
            "title": {
              "type": "string"
            }
          }
        }
      }
    },
    "LineItem": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "readOnly": true,
          "description": "Server-set line item id. Ignored on input."
        },
        "product_name": {
          "type": [
            "string",
            "null"
          ]
        },
        "product_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "product_quantity": {
          "type": [
            "number",
            "null"
          ],
          "format": "float"
        },
        "quantity_outstanding": {
          "type": [
            "number",
            "null"
          ],
          "format": "float",
          "description": "Quantity still to be fulfilled on this line item — left to deliver on a `delivery` order, left to collect on a `pickup` order. Equal to `product_quantity` before anything is fulfilled, a value in between after a partial fulfillment, `0` when exactly the ordered quantity has been fulfilled, and **negative** when more than the ordered quantity was fulfilled. Subtract it from `product_quantity` for the amount the driver has fulfilled. **Read-only:** drivers record fulfillment in the SmartRoutes mobile app; it cannot be set through this API. Notes: `null` — not `0` — when the line item is not tracked, so treat null as unknown rather than as fully fulfilled; an over-fulfillment is reported as recorded rather than clamped; stays at `product_quantity` on `shipment` orders, which are dual-leg and not yet tracked. A value still equal to `product_quantity` does not distinguish an untouched line item from one a driver attended and fulfilled nothing on — read `status` for that (`UNDELIVERED` means attended)."
        },
        "capacities": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Capacity"
          }
        },
        "status": {
          "allOf": [
            {
              "$ref": "#/$defs/LineItemStatus"
            }
          ],
          "nullable": true
        },
        "date": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "custom_fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomField"
          }
        }
      }
    },
    "LineItemRef": {
      "type": "object",
      "description": "A line item reference: its id only.",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "readOnly": true,
          "description": "Server-set line item id."
        }
      }
    },
    "LineItemStatus": {
      "type": "string",
      "description": "Per-line-item status. `PARTIALLY_DELIVERED` appears when a line item has been partly fulfilled — partly collected on a `pickup` order or partly delivered on a `delivery` order; how much is left to fulfil is in `quantity_outstanding`. There is no separate picked-up status: completed and partial pickups both use the `DELIVERED` family. `UNDELIVERED` covers both \"attended, nothing fulfilled\" (in which case `quantity_outstanding` still equals `product_quantity`) and a failed visit. The other `PARTIALLY_*` values are aggregates and apply only at the order level (see `OrderStatus`). Historical rows may still carry legacy values (`CANCEL`, `COMPLETED`, `DECLINED`, `NOT RECEIVED`, `ON HOLD`, `RETURNED`); these are listed for backward compatibility but are no longer written by current SR code.\n\nValues SmartRoutes writes: `BOOKED`, `BOOKING_DECLINED`, `DELIVERED`, `LOADED`, `OPEN`, `PARTIALLY_DELIVERED`, `READY_FOR_COLLECTION`, `ROUTED`, `UNDELIVERED`, `WAITING_CONFIRMATION`.\n\nThis is **not** a closed set. Your organisation can define its own statuses, and any of them can appear here. Call `GET /order-statuses` for the full list your organisation can use, and treat this field as a free string rather than an enum."
    },
    "Order": {
      "type": "object",
      "description": "An order. Property set is the union of fields returned by list and get-by-id paths; individual endpoints may return a subset.",
      "properties": {
        "id": {
          "type": "integer"
        },
        "order_number": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "delivery",
            "pickup",
            "shipment"
          ],
          "description": "delivery, pickup or shipment. Always set — required on every create path and enforced NOT NULL at the database."
        },
        "status": {
          "$ref": "#/$defs/OrderStatus"
        },
        "priority": {
          "type": [
            "string",
            "null"
          ],
          "description": "LOW, MEDIUM, HIGH, or null."
        },
        "parts": {
          "type": [
            "integer",
            "null"
          ]
        },
        "delivery_address": {
          "type": [
            "string",
            "null"
          ]
        },
        "delivery_lat": {
          "type": [
            "number",
            "null"
          ]
        },
        "delivery_lng": {
          "type": [
            "number",
            "null"
          ]
        },
        "delivery_notes": {
          "type": [
            "string",
            "null"
          ]
        },
        "delivery_available_days": {
          "type": "array",
          "items": {
            "type": "integer"
          },
          "description": "Days of week the delivery may be made. Empty array when the order carries no day restriction."
        },
        "delivery_duration": {
          "type": [
            "number",
            "null"
          ],
          "description": "Service duration in minutes. Null when unset — not the same as 0."
        },
        "delivery_date": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "delivery_contact_name": {
          "type": [
            "string",
            "null"
          ]
        },
        "delivery_contact_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "delivery_contact_email": {
          "type": [
            "string",
            "null"
          ]
        },
        "pickup_address": {
          "type": [
            "string",
            "null"
          ]
        },
        "pickup_duration": {
          "type": [
            "number",
            "null"
          ]
        },
        "pickup_lat": {
          "type": [
            "number",
            "null"
          ]
        },
        "pickup_lng": {
          "type": [
            "number",
            "null"
          ]
        },
        "pickup_notes": {
          "type": [
            "string",
            "null"
          ]
        },
        "pickup_contact_name": {
          "type": [
            "string",
            "null"
          ]
        },
        "pickup_contact_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "pickup_contact_email": {
          "type": [
            "string",
            "null"
          ]
        },
        "pickup_available_days": {
          "type": "array",
          "items": {
            "type": "integer"
          },
          "description": "Days of week the pickup may be made. Empty array when the order carries no day restriction."
        },
        "customer": {
          "$ref": "#/$defs/Customer"
        },
        "capacities": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Capacity"
          }
        },
        "custom_fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomField"
          }
        },
        "time_windows": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TimeWindow"
          }
        },
        "skills": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "attachments": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "name": {
                "type": "string"
              }
            }
          }
        },
        "vehicle_assignment": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "properties": {
              "vehicle_id": {
                "type": "integer"
              }
            }
          }
        },
        "emails": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "email": {
                "type": "string"
              }
            }
          }
        },
        "third_party": {
          "type": "object",
          "properties": {
            "id": {
              "type": [
                "integer",
                "null"
              ]
            }
          }
        },
        "order_exchange": {
          "type": [
            "object",
            "null"
          ],
          "description": "Present when this order is one half of an exchange (a drop + collect served together by one vehicle). The two halves share exchange_id.",
          "properties": {
            "id": {
              "type": "integer",
              "readOnly": true
            },
            "order_id": {
              "type": "integer",
              "readOnly": true,
              "description": "Server-set: the id of this order. Never accepted as input."
            },
            "exchange_id": {
              "type": "string",
              "readOnly": true,
              "description": "Server-minted uuid identifying the pair — identical on both halves. Never accepted as input."
            },
            "partner_order_id": {
              "type": "integer",
              "readOnly": true,
              "description": "Server-set: the other half's order id. Never accepted as input."
            },
            "reference": {
              "type": [
                "string",
                "null"
              ],
              "description": "Customer-supplied swap reference (display only). The only client-settable field — provide it on the create request (order_exchange.reference)."
            }
          }
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "stops": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/OrderStop"
          }
        },
        "line_items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LineItem"
          }
        },
        "created": {
          "type": "string",
          "format": "date-time"
        },
        "updated": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "OrderListItem": {
      "description": "An order as returned by GET /orders: `Order` with `line_items` narrowed to `LineItemRef`. Fetch the order with GET /orders/{id} for full line item details.",
      "allOf": [
        {
          "$ref": "#/$defs/Order"
        },
        {
          "type": "object",
          "properties": {
            "line_items": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/LineItemRef"
              }
            }
          }
        }
      ]
    },
    "OrderStatus": {
      "type": "string",
      "description": "Order status. SmartRoutes derives these values from line-item statuses (source: `cORDER_STATUS_TYPES` in `src/models/order-status.js`): `BOOKED`, `BOOKING_DECLINED`, `DELIVERED`, `LOADED`, `OPEN`, `PARTIALLY_BOOKED`, `PARTIALLY_BOOKING_DECLINED`, `PARTIALLY_DELIVERED`, `PARTIALLY_LOADED`, `PARTIALLY_READY_FOR_COLLECTION`, `PARTIALLY_ROUTED`, `PARTIALLY_UNDELIVERED`, `PARTIALLY_WAITING_CONFIRMATION`, `READY_FOR_COLLECTION`, `ROUTED`, `UNDELIVERED`, `WAITING_CONFIRMATION`.\n\nThis is **not** a closed set. Your organisation can define its own statuses, and any of them can appear here. Call `GET /order-statuses` for the full list your organisation can use, and treat this field as a free string rather than an enum."
    },
    "OrderStop": {
      "type": "object",
      "description": "A stop as returned nested under an order (GET /orders/{id}). Composes `StopBase` and adds the parent `route` reference and the stop's own `custom_fields`. The per-stop `orders` array is omitted — the caller already has the order.",
      "allOf": [
        {
          "$ref": "#/$defs/StopBase"
        },
        {
          "type": "object",
          "properties": {
            "custom_fields": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/CustomField"
              }
            },
            "route": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "date": {
                  "type": "string",
                  "format": "date"
                },
                "started_ts": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                }
              }
            }
          }
        }
      ]
    },
    "StopBase": {
      "type": "object",
      "description": "Fields common to every stop projection, independent of the resource the stop is nested under. `Stop` (route context) and `OrderStop` (order context) each compose this base. POD-related fields populate as the stop is completed.",
      "properties": {
        "id": {
          "type": "integer"
        },
        "route_id": {
          "type": "integer"
        },
        "address": {
          "type": "string"
        },
        "postcode": {
          "type": "string"
        },
        "phone": {
          "type": [
            "string",
            "null"
          ]
        },
        "lat": {
          "type": "number"
        },
        "lng": {
          "type": "number"
        },
        "planned_distance": {
          "type": "number"
        },
        "arrival_date": {
          "type": "string",
          "format": "date"
        },
        "departure_date": {
          "type": "string",
          "format": "date"
        },
        "estimated_arrival_time": {
          "type": "string",
          "description": "HH:mm or HH:mm:ss"
        },
        "estimated_departure_time": {
          "type": "string",
          "description": "HH:mm or HH:mm:ss"
        },
        "actual_completed_ts": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "actual_completed_lat": {
          "type": [
            "number",
            "null"
          ]
        },
        "actual_completed_lng": {
          "type": [
            "number",
            "null"
          ]
        },
        "delivery_notes": {
          "type": [
            "string",
            "null"
          ]
        },
        "driver_notes": {
          "type": [
            "string",
            "null"
          ],
          "description": "The driver's internal note on the stop, for your team. Not shown to the recipient."
        },
        "driver_external_note": {
          "type": [
            "string",
            "null"
          ],
          "description": "The driver's note for the recipient, taken with \"Take Note For Recipient\" in the driver app. The tracking portal can show it to the recipient. Separate from `driver_notes`: a stop can have either, both or neither."
        },
        "actual_arrival_time": {
          "type": [
            "string",
            "null"
          ]
        },
        "actual_duration": {
          "type": [
            "string",
            "null"
          ],
          "description": "Total time the driver was checked in at the stop, as a decimal string with two places (e.g. `\"60.00\"`). Parse it as a number. `null` when the stop has no check-ins."
        },
        "signature": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "signature_lat": {
          "type": [
            "number",
            "null"
          ]
        },
        "signature_lng": {
          "type": [
            "number",
            "null"
          ]
        },
        "signed_by": {
          "type": [
            "string",
            "null"
          ]
        },
        "photos": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string",
            "format": "uri"
          },
          "description": "URLs to proof-of-delivery photos for this stop. A photo appears here as soon as it is uploaded and synced, which may be before compression has finished — following the URL of a photo that is still compressing returns `202 Accepted` with a `Retry-After` header (see the photo endpoint), so be prepared to retry. `null` when there are none."
        },
        "tracking_link": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "vehicle_assignment": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "vehicle_id": {
              "type": "integer"
            }
          }
        },
        "directions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "instruction": {
                "type": "string"
              }
            }
          }
        },
        "driver_questionnaire_submissions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DriverQuestionnaireSubmission"
          }
        },
        "failed_reason": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "reason": {
              "type": "string"
            }
          }
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "available_days": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "emails": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "properties": {
              "email": {
                "type": "string"
              }
            }
          }
        },
        "driver_phone_calls": {
          "type": "array",
          "description": "Calls the driver placed to this stop's contact number from the driver app, oldest first. `[]` when there are none.\n\n**These are call *attempts*, not call records.** The app hands a `tel:` URL to the device's dialler and the OS takes over, so SmartRoutes never observes the call itself. There is deliberately no status, no duration and no answered/unanswered flag — that information does not exist. Inbound calls, and calls placed outside the driver app, are not recorded at all.\n\n`initiated_at` is the driver device's own clock at the moment the call was placed; `recorded_at` is when our servers received it. Drivers work offline, so these can differ by hours, and a call can arrive with an `initiated_at` well before the `recorded_at` of calls you have already seen. Poll on `recorded_at`, not `initiated_at`, if you are looking for new activity.\n\nAbsence is not proof no call was made: on iOS, a call placed with no GPS fix available is not recorded.",
          "items": {
            "type": "object",
            "properties": {
              "initiated_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "When the driver placed the call, from the device clock. `null` if the app did not record a usable timestamp."
              },
              "recorded_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "When our servers received the record. Later than `initiated_at` — by hours if the driver was working offline."
              },
              "lat": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Driver's latitude when the call was placed. `null` when no GPS fix was available."
              },
              "lng": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Driver's longitude when the call was placed. `null` when no GPS fix was available."
              }
            }
          }
        }
      }
    },
    "TimeWindow": {
      "type": "object",
      "properties": {
        "from": {
          "type": [
            "string",
            "null"
          ],
          "description": "HH:mm:ss"
        },
        "to": {
          "type": [
            "string",
            "null"
          ],
          "description": "HH:mm:ss"
        },
        "type": {
          "type": [
            "string",
            "null"
          ],
          "description": "`delivery` or `pickup`; `null` for an untyped window."
        }
      }
    }
  }
}