{
  "openapi": "3.1.0",
  "info": {
    "title": "SSCCAPI — Validation, EDI & GS1 Pallet Label API",
    "version": "5.11.0",
    "description": "High-performance Cloudflare Edge REST API for Serial Shipping Container Code (SSCC-18) validation,\ncheck digit calculation (GS1 Modulo 10), range expansion, country/company prefix lookup,\nmulti-format file extraction (UN/EDIFACT, SAP IDoc, XML, CSV, TXT), and Dual 1D GS1-128 + 2D QR\nDigital Link pallet labels & Zebra ZPL-II generation.\n",
    "contact": {
      "name": "birth1mark",
      "url": "https://ssccapi.com/"
    },
    "license": {
      "name": "MIT",
      "url": "https://github.com/birth1mark/sscc-check/blob/main/LICENSE"
    }
  },
  "servers": [
    {
      "url": "https://ssccapi.com",
      "description": "Primary Unified Edge API — Validation, EDI Extraction, Barcodes, ZPL & Pallet Labels"
    },
    {
      "url": "https://sscc-labels.birth1mark.workers.dev",
      "description": "Direct Edge Mirror — Pallet Labels, ZPL & 2D QR Digital Link API"
    },
    {
      "url": "https://sscc.birth1mark.workers.dev",
      "description": "Direct Edge Mirror — Free Validation & EDI Extraction API"
    }
  ],
  "paths": {
    "/validate": {
      "get": {
        "summary": "Validate SSCC-18 Code",
        "description": "Validates an 18-digit SSCC or 20-digit code with Application Identifier (00).\nCalculates the GS1 Modulo 10 check digit and returns prefix country metadata.\n",
        "parameters": [
          {
            "name": "sscc",
            "in": "query",
            "required": true,
            "description": "18-digit SSCC or 20-digit SSCC with leading 00",
            "schema": {
              "type": "string",
              "example": "356012345600000016"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Validation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input length or format",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/generate": {
      "get": {
        "summary": "Generate Check Digit for 17-digit Body",
        "description": "Computes the GS1 Modulo 10 check digit for a 17-digit SSCC payload and returns the full 18-digit SSCC.",
        "parameters": [
          {
            "name": "body",
            "in": "query",
            "required": true,
            "description": "17-digit SSCC payload without check digit",
            "schema": {
              "type": "string",
              "example": "35601234560000001"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Generation result with full SSCC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body length",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/range": {
      "get": {
        "summary": "Generate Sequential Range of SSCCs",
        "description": "Expands a consecutive range of SSCC numbers (up to 500 codes per request) with calculated check digits.",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "description": "Starting 17-digit payload or 18-digit SSCC",
            "schema": {
              "type": "string",
              "example": "35601234560000001"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "description": "Ending 17-digit payload or 18-digit SSCC",
            "schema": {
              "type": "string",
              "example": "35601234560000020"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of sequential SSCCs with check digits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RangeResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid range or count exceeds 500",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/prefix": {
      "get": {
        "summary": "Lookup GS1 Prefix & Country",
        "description": "Returns the GS1 member organization / country corresponding to the SSCC prefix.",
        "parameters": [
          {
            "name": "sscc",
            "in": "query",
            "required": true,
            "description": "18-digit SSCC",
            "schema": {
              "type": "string",
              "example": "356012345600000016"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Prefix metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrefixResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid SSCC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/extract": {
      "post": {
        "summary": "Extract SSCCs from Raw Text / File",
        "description": "Parses UN/EDIFACT (DESADV, ORDERS), SAP IDoc (DELVRY, INVOIC), XML, CSV, or plain text\npayloads (up to 1 MB) and extracts all detected SSCC codes with validation status.\n",
        "requestBody": {
          "required": true,
          "content": {
            "text/plain": {
              "schema": {
                "type": "string",
                "example": "UNA:+.? 'UNB+UNOC:3...GIN+BJ+356012345600000016'..."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Extraction summary with all found SSCCs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExtractResponse"
                }
              }
            }
          },
          "400": {
            "description": "Empty request body or payload exceeds limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Service Health Check",
        "description": "Returns API status, version, and available endpoints.",
        "responses": {
          "200": {
            "description": "Service status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "version": {
                      "type": "string",
                      "example": "1.2.2"
                    },
                    "endpoints": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/labels": {
      "post": {
        "summary": "Generate Batch GS1 Pallet Labels (1D GS1-128 + 2D QR Digital Link / ZPL / HTML / SVG)",
        "parameters": [
          {
            "name": "X-API-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ssccs": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "gcp": {
                    "type": "string",
                    "example": "5601234"
                  },
                  "extension": {
                    "type": "string",
                    "example": "0"
                  },
                  "startSerial": {
                    "type": "integer",
                    "example": 1001
                  },
                  "quantity": {
                    "type": "integer",
                    "example": 5
                  },
                  "layout": {
                    "type": "string",
                    "enum": [
                      "full",
                      "barcode-only"
                    ],
                    "default": "full"
                  },
                  "symbology": {
                    "type": "string",
                    "enum": [
                      "dual",
                      "both",
                      "gs1-128",
                      "qr"
                    ],
                    "default": "dual"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "json",
                      "zpl",
                      "html",
                      "svg"
                    ],
                    "default": "json"
                  },
                  "paperSize": {
                    "type": "string",
                    "enum": [
                      "a5",
                      "a6",
                      "thermal"
                    ],
                    "default": "a5"
                  },
                  "sender": {
                    "type": "string"
                  },
                  "recipient": {
                    "type": "string"
                  },
                  "contents": {
                    "type": "string"
                  },
                  "weight": {
                    "type": "string"
                  },
                  "orderNo": {
                    "type": "string"
                  },
                  "gtin": {
                    "type": "string"
                  },
                  "unitCount": {
                    "type": "string"
                  },
                  "batchNo": {
                    "type": "string"
                  },
                  "expiryDate": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generated GS1 labels (JSON, ZPL-II, HTML, or SVG)"
          },
          "402": {
            "description": "Free quota (25 labels) exceeded or Pro credits exhausted"
          }
        }
      }
    },
    "/v1/barcode": {
      "get": {
        "summary": "Generate Standalone SSCC Barcode (1D GS1-128, 2D QR Digital Link, or Both)",
        "parameters": [
          {
            "name": "sscc",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "356012345600000016"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "both",
                "dual",
                "gs1-128",
                "qr"
              ],
              "default": "both"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "svg",
                "json",
                "zpl"
              ],
              "default": "svg"
            }
          },
          {
            "name": "batch",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Standalone barcode in Vector SVG (image/svg+xml), JSON, or Zebra ZPL-II"
          }
        }
      }
    },
    "/v1/qr": {
      "get": {
        "summary": "Generate Standalone 2D GS1 Digital Link QR Code (SVG)",
        "parameters": [
          {
            "name": "sscc",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "356012345600000016"
            }
          },
          {
            "name": "batch",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "example": "LOT-99A"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Vector SVG QR Code (image/svg+xml)"
          }
        }
      }
    },
    "/v1/quota": {
      "get": {
        "summary": "Check Remaining Free or Pro Label Credits",
        "parameters": [
          {
            "name": "gcp",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "example": "5601234"
            }
          },
          {
            "name": "X-API-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current quota balance and available credit plans"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ValidationResponse": {
        "type": "object",
        "properties": {
          "input": {
            "type": "string",
            "example": "356012345600000016"
          },
          "sscc": {
            "type": "string",
            "example": "356012345600000016"
          },
          "formatted": {
            "type": "string",
            "example": "(00)356012345600000016"
          },
          "valid": {
            "type": "boolean",
            "example": true
          },
          "checkDigit": {
            "type": "object",
            "properties": {
              "provided": {
                "type": "integer",
                "example": 6
              },
              "expected": {
                "type": "integer",
                "example": 6
              }
            }
          },
          "gs1": {
            "$ref": "#/components/schemas/GS1Metadata"
          }
        }
      },
      "GenerationResponse": {
        "type": "object",
        "properties": {
          "input": {
            "type": "string",
            "example": "35601234560000001"
          },
          "body": {
            "type": "string",
            "example": "35601234560000001"
          },
          "checkDigit": {
            "type": "integer",
            "example": 6
          },
          "sscc": {
            "type": "string",
            "example": "356012345600000016"
          },
          "formatted": {
            "type": "string",
            "example": "(00)356012345600000016"
          },
          "gs1": {
            "$ref": "#/components/schemas/GS1Metadata"
          }
        }
      },
      "RangeResponse": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string",
            "example": "35601234560000001"
          },
          "to": {
            "type": "string",
            "example": "35601234560000020"
          },
          "count": {
            "type": "integer",
            "example": 20
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "sscc": {
                  "type": "string",
                  "example": "356012345600000016"
                },
                "formatted": {
                  "type": "string",
                  "example": "(00)356012345600000016"
                },
                "checkDigit": {
                  "type": "integer",
                  "example": 6
                }
              }
            }
          }
        }
      },
      "PrefixResponse": {
        "type": "object",
        "properties": {
          "sscc": {
            "type": "string",
            "example": "356012345600000016"
          },
          "prefix": {
            "type": "string",
            "example": "560"
          },
          "country": {
            "type": "string",
            "example": "Portugal"
          },
          "countryCode": {
            "type": "string",
            "example": "PT"
          },
          "flag": {
            "type": "string",
            "example": "🇵🇹"
          }
        }
      },
      "ExtractResponse": {
        "type": "object",
        "properties": {
          "format": {
            "type": "string",
            "example": "edifact"
          },
          "found": {
            "type": "integer",
            "example": 1
          },
          "valid": {
            "type": "integer",
            "example": 1
          },
          "invalid": {
            "type": "integer",
            "example": 0
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ValidationResponse"
            }
          }
        }
      },
      "GS1Metadata": {
        "type": "object",
        "properties": {
          "extensionDigit": {
            "type": "integer",
            "example": 3
          },
          "prefix": {
            "type": "string",
            "example": "560"
          },
          "country": {
            "type": "string",
            "example": "Portugal"
          },
          "countryCode": {
            "type": "string",
            "example": "PT"
          },
          "flag": {
            "type": "string",
            "example": "🇵🇹"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "example": "Invalid length: expected 18 digits (or 20 with AI prefix), got 15"
          }
        }
      }
    }
  }
}