{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/sendmypaper-com/json-schema/sendmypaper-com-batch-schema.json",
  "title": "Batch",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/sendmypaper-com-openapi.json#/components/schemas/Batch",
  "type": "object",
  "required": [
    "batch",
    "orders"
  ],
  "properties": {
    "batch": {
      "type": "object",
      "required": [
        "id",
        "count",
        "url",
        "price"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Batch id, batch_…"
        },
        "count": {
          "type": "integer",
          "description": "Number of recipients (one order each)"
        },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Batch page listing every recipient with links to each preview"
        },
        "checkout_url": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri",
          "description": "One payment link for every unpaid order in the batch; null once all are paid"
        },
        "price": {
          "type": "object",
          "properties": {
            "amount_cents": {
              "type": "integer"
            },
            "currency": {
              "type": "string"
            },
            "display": {
              "type": "string"
            }
          },
          "description": "Total for the whole batch"
        },
        "discount": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "amount_cents": {
              "type": "integer"
            },
            "display": {
              "type": "string"
            },
            "reason": {
              "type": "string"
            }
          },
          "description": "First-order discount across the batch, already taken off price"
        }
      }
    },
    "orders": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Order"
      },
      "description": "One order per recipient, in the order given"
    }
  },
  "$defs": {
    "Address": {
      "type": "object",
      "required": [
        "name",
        "line1",
        "city",
        "state",
        "zip"
      ],
      "properties": {
        "name": {
          "type": "string",
          "maxLength": 60
        },
        "company": {
          "type": "string",
          "maxLength": 60
        },
        "line1": {
          "type": "string",
          "maxLength": 64,
          "description": "Street address"
        },
        "line2": {
          "type": "string",
          "maxLength": 64,
          "description": "Apartment, suite, unit"
        },
        "city": {
          "type": "string",
          "maxLength": 40
        },
        "state": {
          "type": "string",
          "description": "Two-letter US state or territory code"
        },
        "zip": {
          "type": "string",
          "pattern": "^\\d{5}(-\\d{4})?$"
        }
      },
      "description": "A US address (recipients are always in the US, including territories and APO/FPO/DPO)."
    },
    "Order": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "object": {
          "type": "string",
          "enum": [
            "postcard",
            "letter"
          ]
        },
        "product": {
          "type": "string",
          "enum": [
            "postcard_4x6",
            "postcard_6x9",
            "postcard_6x11",
            "letter",
            "letter_certified",
            "letter_certified_rr"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "awaiting_payment",
            "paid",
            "printing",
            "mailed",
            "cancelled",
            "refunded"
          ]
        },
        "status_detail": {
          "type": "string"
        },
        "price": {
          "type": "object",
          "properties": {
            "amount_cents": {
              "type": "integer"
            },
            "currency": {
              "type": "string"
            },
            "display": {
              "type": "string"
            }
          }
        },
        "to": {
          "$ref": "#/$defs/Address"
        },
        "from": {
          "$ref": "#/$defs/SenderAddress"
        },
        "content": {
          "type": "object"
        },
        "checkout_url": {
          "type": [
            "string",
            "null"
          ],
          "description": "Where the person pays. Null once paid or closed. Never expires."
        },
        "order_url": {
          "type": "string",
          "description": "Human-readable status page"
        },
        "preview_url": {
          "type": "string",
          "description": "Exact print preview"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "paid_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "mailed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "events": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "at": {
                "type": "string"
              },
              "status": {
                "type": "string"
              },
              "note": {
                "type": "string"
              }
            }
          }
        },
        "certified": {
          "type": "string",
          "enum": [
            "none",
            "certified",
            "certified_return_receipt"
          ],
          "description": "Letters only: the USPS extra service."
        },
        "tracking": {
          "type": [
            "object",
            "null"
          ],
          "description": "USPS tracking once the piece is accepted (certified letters always get one).",
          "properties": {
            "number": {
              "type": "string"
            },
            "url": {
              "type": "string",
              "format": "uri"
            }
          }
        },
        "batch_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Set when the order is part of a batch (created with `recipients`). Its checkout_url is then the batch's single payment link."
        }
      }
    },
    "SenderAddress": {
      "type": "object",
      "required": [
        "name",
        "line1",
        "city"
      ],
      "description": "Return address. It may be outside the US: set `country`. For a US address (no `country`, or `US`), `state` and `zip` are required and follow the US rules; elsewhere `state` is the region and `zip` the postcode, both optional.",
      "properties": {
        "name": {
          "type": "string",
          "maxLength": 60
        },
        "company": {
          "type": "string",
          "maxLength": 60
        },
        "line1": {
          "type": "string",
          "maxLength": 64,
          "description": "Street address"
        },
        "line2": {
          "type": "string",
          "maxLength": 64,
          "description": "Apartment, suite, unit"
        },
        "city": {
          "type": "string",
          "maxLength": 40,
          "description": "City or town"
        },
        "state": {
          "type": "string",
          "maxLength": 40,
          "description": "US: two-letter state or territory code (required). Elsewhere: region, county or province, if any"
        },
        "zip": {
          "type": "string",
          "maxLength": 12,
          "description": "US: 5-digit ZIP or ZIP+4 (required). Elsewhere: postcode"
        },
        "country": {
          "type": "string",
          "pattern": "^[A-Za-z]{2}$",
          "default": "US",
          "description": "Two-letter ISO 3166-1 country code of the return address, e.g. GB. Defaults to US. US territories use US with their state code."
        }
      }
    }
  }
}