{
  "openapi": "3.1.0",
  "info": {
    "title": "BrandGate API",
    "version": "1.0.0",
    "description": "Read orders, products, stock, customers and invoices, acknowledge orders and set stock from your ERP. Authenticate with an organization API key or an OAuth access token as `Authorization: Bearer <token>`."
  },
  "servers": [
    {
      "url": "https://api.brandgate.dev"
    }
  ],
  "security": [
    {
      "apiKey": []
    },
    {
      "oauth2": []
    }
  ],
  "tags": [
    {
      "name": "orders",
      "description": "Orders placed by resellers."
    },
    {
      "name": "products",
      "description": "The product catalogue."
    },
    {
      "name": "inventory",
      "description": "Stock levels per SKU."
    },
    {
      "name": "customers",
      "description": "Resellers buying from the organization."
    },
    {
      "name": "invoices",
      "description": "Invoices sent to resellers."
    },
    {
      "name": "webhook_endpoints",
      "description": "Where BrandGate sends events."
    }
  ],
  "paths": {
    "/v1/orders": {
      "get": {
        "operationId": "ordersList",
        "summary": "List orders",
        "description": "Orders oldest change first. Use updated_since and the cursor to sync changes.\n\nRequires the `orders:read` scope.",
        "tags": [
          "orders"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "orders:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,200}$"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "pending_payment",
                "processing",
                "shipped",
                "delivered",
                "cancelled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "object": {
                            "const": "order"
                          },
                          "number": {
                            "type": "string",
                            "maxLength": 100
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "draft",
                              "pending_payment",
                              "processing",
                              "shipped",
                              "delivered",
                              "cancelled"
                            ]
                          },
                          "order_date": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                          },
                          "due_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                          },
                          "currency": {
                            "type": "string",
                            "maxLength": 3
                          },
                          "total": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "vat": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "total_excl_vat": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "discount_amount": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "po_reference": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "notes": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 4000
                          },
                          "customer": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "properties": {
                              "id": {
                                "type": "string",
                                "format": "uuid"
                              },
                              "name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 500
                              }
                            },
                            "required": [
                              "id",
                              "name"
                            ],
                            "additionalProperties": false
                          },
                          "ship_to": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": {}
                          },
                          "lines": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "format": "uuid"
                                },
                                "product_id": {
                                  "type": "string",
                                  "format": "uuid"
                                },
                                "sku": {
                                  "type": [
                                    "string",
                                    "null"
                                  ],
                                  "maxLength": 200
                                },
                                "name": {
                                  "type": [
                                    "string",
                                    "null"
                                  ],
                                  "maxLength": 500
                                },
                                "quantity": {
                                  "type": "integer"
                                },
                                "unit_price": {
                                  "type": "string",
                                  "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                                },
                                "vat_rate": {
                                  "type": "string",
                                  "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                                },
                                "line_total": {
                                  "type": "string",
                                  "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                                }
                              },
                              "required": [
                                "id",
                                "product_id",
                                "sku",
                                "name",
                                "quantity",
                                "unit_price",
                                "vat_rate",
                                "line_total"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "external_reference": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "properties": {
                              "number": {
                                "type": "string",
                                "maxLength": 100
                              },
                              "acknowledged_at": {
                                "type": "string",
                                "format": "date-time"
                              },
                              "note": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 500
                              }
                            },
                            "required": [
                              "number",
                              "acknowledged_at",
                              "note"
                            ],
                            "additionalProperties": false
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "id",
                          "object",
                          "number",
                          "status",
                          "order_date",
                          "due_date",
                          "currency",
                          "total",
                          "vat",
                          "total_excl_vat",
                          "discount_amount",
                          "po_reference",
                          "notes",
                          "customer",
                          "ship_to",
                          "lines",
                          "external_reference",
                          "created_at",
                          "updated_at"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orders/{id}": {
      "get": {
        "operationId": "ordersGet",
        "summary": "Get an order",
        "description": "One order with its lines and any ERP acknowledgement.\n\nRequires the `orders:read` scope.",
        "tags": [
          "orders"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "orders:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "object": {
                      "const": "order"
                    },
                    "number": {
                      "type": "string",
                      "maxLength": 100
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "draft",
                        "pending_payment",
                        "processing",
                        "shipped",
                        "delivered",
                        "cancelled"
                      ]
                    },
                    "order_date": {
                      "type": "string",
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    "due_date": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    "currency": {
                      "type": "string",
                      "maxLength": 3
                    },
                    "total": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "vat": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "total_excl_vat": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "discount_amount": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "po_reference": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 200
                    },
                    "notes": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 4000
                    },
                    "customer": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "name": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ],
                      "additionalProperties": false
                    },
                    "ship_to": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "additionalProperties": {}
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "product_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "sku": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 500
                          },
                          "quantity": {
                            "type": "integer"
                          },
                          "unit_price": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "vat_rate": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "line_total": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          }
                        },
                        "required": [
                          "id",
                          "product_id",
                          "sku",
                          "name",
                          "quantity",
                          "unit_price",
                          "vat_rate",
                          "line_total"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "external_reference": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "number": {
                          "type": "string",
                          "maxLength": 100
                        },
                        "acknowledged_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "note": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500
                        }
                      },
                      "required": [
                        "number",
                        "acknowledged_at",
                        "note"
                      ],
                      "additionalProperties": false
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "number",
                    "status",
                    "order_date",
                    "due_date",
                    "currency",
                    "total",
                    "vat",
                    "total_excl_vat",
                    "discount_amount",
                    "po_reference",
                    "notes",
                    "customer",
                    "ship_to",
                    "lines",
                    "external_reference",
                    "created_at",
                    "updated_at"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orders/{id}/acknowledge": {
      "post": {
        "operationId": "ordersAcknowledge",
        "summary": "Acknowledge an order",
        "description": "Record the order's number in your ERP. Repeating the same number is safe; a different number for an acknowledged order is refused.\n\nRequires the `orders:write` scope.",
        "tags": [
          "orders"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "orders:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "external_number": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[\\p{L}\\p{N} ._\\-/#:]+$"
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "required": [
                  "external_number"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "object": {
                      "const": "order"
                    },
                    "number": {
                      "type": "string",
                      "maxLength": 100
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "draft",
                        "pending_payment",
                        "processing",
                        "shipped",
                        "delivered",
                        "cancelled"
                      ]
                    },
                    "order_date": {
                      "type": "string",
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    "due_date": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    "currency": {
                      "type": "string",
                      "maxLength": 3
                    },
                    "total": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "vat": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "total_excl_vat": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "discount_amount": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "po_reference": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 200
                    },
                    "notes": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 4000
                    },
                    "customer": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "name": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ],
                      "additionalProperties": false
                    },
                    "ship_to": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "additionalProperties": {}
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "product_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "sku": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 500
                          },
                          "quantity": {
                            "type": "integer"
                          },
                          "unit_price": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "vat_rate": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "line_total": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          }
                        },
                        "required": [
                          "id",
                          "product_id",
                          "sku",
                          "name",
                          "quantity",
                          "unit_price",
                          "vat_rate",
                          "line_total"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "external_reference": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "number": {
                          "type": "string",
                          "maxLength": 100
                        },
                        "acknowledged_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "note": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500
                        }
                      },
                      "required": [
                        "number",
                        "acknowledged_at",
                        "note"
                      ],
                      "additionalProperties": false
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "number",
                    "status",
                    "order_date",
                    "due_date",
                    "currency",
                    "total",
                    "vat",
                    "total_excl_vat",
                    "discount_amount",
                    "po_reference",
                    "notes",
                    "customer",
                    "ship_to",
                    "lines",
                    "external_reference",
                    "created_at",
                    "updated_at"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/products": {
      "get": {
        "operationId": "productsList",
        "summary": "List products",
        "description": "Products oldest change first.\n\nRequires the `products:read` scope.",
        "tags": [
          "products"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "products:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,200}$"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "object": {
                            "const": "product"
                          },
                          "sku": {
                            "type": "string",
                            "maxLength": 200
                          },
                          "name": {
                            "type": "string",
                            "maxLength": 500
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 20000
                          },
                          "category": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "active",
                              "low_stock",
                              "out_of_stock"
                            ]
                          },
                          "unit_price": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "currency": {
                            "type": "string",
                            "maxLength": 3
                          },
                          "vat_rate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "stock": {
                            "type": "integer"
                          },
                          "min_order": {
                            "type": "integer"
                          },
                          "order_increment": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "max_order": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "image_url": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 2000
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "id",
                          "object",
                          "sku",
                          "name",
                          "description",
                          "category",
                          "status",
                          "unit_price",
                          "currency",
                          "vat_rate",
                          "stock",
                          "min_order",
                          "order_increment",
                          "max_order",
                          "image_url",
                          "created_at",
                          "updated_at"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/products/{id}": {
      "get": {
        "operationId": "productsGet",
        "summary": "Get a product",
        "description": "One product.\n\nRequires the `products:read` scope.",
        "tags": [
          "products"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "products:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "object": {
                      "const": "product"
                    },
                    "sku": {
                      "type": "string",
                      "maxLength": 200
                    },
                    "name": {
                      "type": "string",
                      "maxLength": 500
                    },
                    "description": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 20000
                    },
                    "category": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 200
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "low_stock",
                        "out_of_stock"
                      ]
                    },
                    "unit_price": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "currency": {
                      "type": "string",
                      "maxLength": 3
                    },
                    "vat_rate": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "stock": {
                      "type": "integer"
                    },
                    "min_order": {
                      "type": "integer"
                    },
                    "order_increment": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "max_order": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "image_url": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 2000
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "sku",
                    "name",
                    "description",
                    "category",
                    "status",
                    "unit_price",
                    "currency",
                    "vat_rate",
                    "stock",
                    "min_order",
                    "order_increment",
                    "max_order",
                    "image_url",
                    "created_at",
                    "updated_at"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/inventory": {
      "get": {
        "operationId": "inventoryList",
        "summary": "List stock levels",
        "description": "Stock per product SKU, oldest change first.\n\nRequires the `inventory:read` scope.",
        "tags": [
          "inventory"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "inventory:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,200}$"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "object": {
                            "const": "inventory_level"
                          },
                          "product_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "sku": {
                            "type": "string",
                            "maxLength": 200
                          },
                          "stock": {
                            "type": "integer"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "active",
                              "low_stock",
                              "out_of_stock"
                            ]
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "object",
                          "product_id",
                          "sku",
                          "stock",
                          "status",
                          "updated_at"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "inventoryUpdate",
        "summary": "Set stock levels",
        "description": "Set absolute stock per SKU (up to 500 per request). The ERP is the source of truth: BrandGate stock is overwritten, not added to. Answers 409 inventory_managed_by_erp when the company already imports stock from an ERP connected in BrandGate.\n\nRequires the `inventory:write` scope.",
        "tags": [
          "inventory"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "inventory:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "sku": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "quantity": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000
                        }
                      },
                      "required": [
                        "sku",
                        "quantity"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 500
                  }
                },
                "required": [
                  "items"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "inventory_update"
                    },
                    "updated": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "unmatched_skus": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "object",
                    "updated",
                    "unmatched_skus"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/customers": {
      "get": {
        "operationId": "customersList",
        "summary": "List customers",
        "description": "Resellers buying from the organization, oldest change first.\n\nRequires the `customers:read` scope.",
        "tags": [
          "customers"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "customers:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,200}$"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "object": {
                            "const": "customer"
                          },
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 500
                          },
                          "contact_name": {
                            "type": "string",
                            "maxLength": 500
                          },
                          "email": {
                            "type": "string",
                            "maxLength": 320
                          },
                          "phone": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 100
                          },
                          "vat_number": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 100
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "active",
                              "pending",
                              "inactive"
                            ]
                          },
                          "billing_address": {
                            "type": "object",
                            "properties": {
                              "line1": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 500
                              },
                              "city": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 200
                              },
                              "postal_code": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 40
                              },
                              "country": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              }
                            },
                            "required": [
                              "line1",
                              "city",
                              "postal_code",
                              "country"
                            ],
                            "additionalProperties": false
                          },
                          "shipping_address": {
                            "type": "object",
                            "properties": {
                              "line1": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 500
                              },
                              "city": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 200
                              },
                              "postal_code": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 40
                              },
                              "country": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              }
                            },
                            "required": [
                              "line1",
                              "city",
                              "postal_code",
                              "country"
                            ],
                            "additionalProperties": false
                          },
                          "payment_terms_days": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "preferred_currency": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 3
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "id",
                          "object",
                          "name",
                          "contact_name",
                          "email",
                          "phone",
                          "vat_number",
                          "status",
                          "billing_address",
                          "shipping_address",
                          "payment_terms_days",
                          "preferred_currency",
                          "created_at",
                          "updated_at"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/customers/{id}": {
      "get": {
        "operationId": "customersGet",
        "summary": "Get a customer",
        "description": "One reseller.\n\nRequires the `customers:read` scope.",
        "tags": [
          "customers"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "customers:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "object": {
                      "const": "customer"
                    },
                    "name": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 500
                    },
                    "contact_name": {
                      "type": "string",
                      "maxLength": 500
                    },
                    "email": {
                      "type": "string",
                      "maxLength": 320
                    },
                    "phone": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 100
                    },
                    "vat_number": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 100
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "pending",
                        "inactive"
                      ]
                    },
                    "billing_address": {
                      "type": "object",
                      "properties": {
                        "line1": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500
                        },
                        "city": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 200
                        },
                        "postal_code": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 40
                        },
                        "country": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        }
                      },
                      "required": [
                        "line1",
                        "city",
                        "postal_code",
                        "country"
                      ],
                      "additionalProperties": false
                    },
                    "shipping_address": {
                      "type": "object",
                      "properties": {
                        "line1": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500
                        },
                        "city": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 200
                        },
                        "postal_code": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 40
                        },
                        "country": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        }
                      },
                      "required": [
                        "line1",
                        "city",
                        "postal_code",
                        "country"
                      ],
                      "additionalProperties": false
                    },
                    "payment_terms_days": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "preferred_currency": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 3
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "name",
                    "contact_name",
                    "email",
                    "phone",
                    "vat_number",
                    "status",
                    "billing_address",
                    "shipping_address",
                    "payment_terms_days",
                    "preferred_currency",
                    "created_at",
                    "updated_at"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/invoices": {
      "get": {
        "operationId": "invoicesList",
        "summary": "List invoices",
        "description": "Invoices oldest change first.\n\nRequires the `invoices:read` scope.",
        "tags": [
          "invoices"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "invoices:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,200}$"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "paid",
                "overdue",
                "credited"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "object": {
                            "const": "invoice"
                          },
                          "number": {
                            "type": "string",
                            "maxLength": 100
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "pending",
                              "paid",
                              "overdue",
                              "credited"
                            ]
                          },
                          "invoice_date": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                          },
                          "due_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                          },
                          "paid_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                          },
                          "currency": {
                            "type": "string",
                            "maxLength": 3
                          },
                          "total": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "vat": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "ocr_reference": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 100
                          },
                          "order_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "uuid"
                          },
                          "customer_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "lines": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "product_name": {
                                  "type": "string",
                                  "maxLength": 500
                                },
                                "sku": {
                                  "type": [
                                    "string",
                                    "null"
                                  ],
                                  "maxLength": 200
                                },
                                "quantity": {
                                  "type": "string",
                                  "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                                },
                                "unit_price": {
                                  "type": "string",
                                  "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                                },
                                "vat_rate": {
                                  "type": "string",
                                  "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                                },
                                "line_total": {
                                  "type": "string",
                                  "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                                }
                              },
                              "required": [
                                "product_name",
                                "sku",
                                "quantity",
                                "unit_price",
                                "vat_rate",
                                "line_total"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "id",
                          "object",
                          "number",
                          "status",
                          "invoice_date",
                          "due_date",
                          "paid_date",
                          "currency",
                          "total",
                          "vat",
                          "ocr_reference",
                          "order_id",
                          "customer_id",
                          "lines",
                          "created_at",
                          "updated_at"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/invoices/{id}": {
      "get": {
        "operationId": "invoicesGet",
        "summary": "Get an invoice",
        "description": "One invoice with its lines.\n\nRequires the `invoices:read` scope.",
        "tags": [
          "invoices"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "invoices:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "object": {
                      "const": "invoice"
                    },
                    "number": {
                      "type": "string",
                      "maxLength": 100
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "paid",
                        "overdue",
                        "credited"
                      ]
                    },
                    "invoice_date": {
                      "type": "string",
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    "due_date": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    "paid_date": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    "currency": {
                      "type": "string",
                      "maxLength": 3
                    },
                    "total": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "vat": {
                      "type": "string",
                      "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                    },
                    "ocr_reference": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 100
                    },
                    "order_id": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uuid"
                    },
                    "customer_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "product_name": {
                            "type": "string",
                            "maxLength": 500
                          },
                          "sku": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "quantity": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "unit_price": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "vat_rate": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          },
                          "line_total": {
                            "type": "string",
                            "pattern": "^-?\\d{1,15}(\\.\\d{1,6})?$"
                          }
                        },
                        "required": [
                          "product_name",
                          "sku",
                          "quantity",
                          "unit_price",
                          "vat_rate",
                          "line_total"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "number",
                    "status",
                    "invoice_date",
                    "due_date",
                    "paid_date",
                    "currency",
                    "total",
                    "vat",
                    "ocr_reference",
                    "order_id",
                    "customer_id",
                    "lines",
                    "created_at",
                    "updated_at"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/webhook_endpoints": {
      "get": {
        "operationId": "webhooksList",
        "summary": "List webhook endpoints",
        "description": "The organization's webhook endpoints.\n\nRequires the `webhooks:read` scope.",
        "tags": [
          "webhook_endpoints"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "webhooks:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "object": {
                            "const": "webhook_endpoint"
                          },
                          "url": {
                            "type": "string",
                            "format": "uri"
                          },
                          "events": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "enum": [
                                "order.created",
                                "order.updated",
                                "invoice.created",
                                "invoice.updated",
                                "product.stock_low"
                              ]
                            }
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "enabled",
                              "disabled"
                            ]
                          },
                          "disabled_reason": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "id",
                          "object",
                          "url",
                          "events",
                          "description",
                          "status",
                          "disabled_reason",
                          "created_at"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "webhooksCreate",
        "summary": "Create a webhook endpoint",
        "description": "Events are delivered only for scopes the caller holds. The signing secret is returned once.\n\nRequires the `webhooks:write` scope.",
        "tags": [
          "webhook_endpoints"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "webhooks:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "maxLength": 2000,
                    "format": "uri"
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "order.created",
                        "order.updated",
                        "invoice.created",
                        "invoice.updated",
                        "product.stock_low"
                      ]
                    },
                    "minItems": 1,
                    "maxItems": 5
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": [
                  "url",
                  "events"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "object": {
                      "const": "webhook_endpoint"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "enum": [
                          "order.created",
                          "order.updated",
                          "invoice.created",
                          "invoice.updated",
                          "product.stock_low"
                        ]
                      }
                    },
                    "description": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 200
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "enabled",
                        "disabled"
                      ]
                    },
                    "disabled_reason": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 200
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "secret": {
                      "type": "string",
                      "pattern": "^whsec_[A-Za-z0-9_-]{43}$"
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "url",
                    "events",
                    "description",
                    "status",
                    "disabled_reason",
                    "created_at",
                    "secret"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/webhook_endpoints/{id}": {
      "delete": {
        "operationId": "webhooksDelete",
        "summary": "Delete a webhook endpoint",
        "description": "Stops deliveries to the endpoint.\n\nRequires the `webhooks:write` scope.",
        "tags": [
          "webhook_endpoints"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "oauth2": [
              "webhooks:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "headers": {
              "Request-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "object": {
                      "const": "webhook_endpoint"
                    },
                    "deleted": {
                      "const": true
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "deleted"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. `error.message` says which field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown, expired or revoked credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The credentials lack the scope this operation needs.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait until `X-RateLimit-Reset` (or `Retry-After` seconds).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "order.created": {
      "post": {
        "summary": "order.created",
        "description": "Sent when order is created. Verify the `BrandGate-Signature` header, then fetch the object for its current state.",
        "parameters": [
          {
            "name": "BrandGate-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1760950000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Event"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Return any 2xx within 10 seconds to acknowledge."
          }
        }
      }
    },
    "order.updated": {
      "post": {
        "summary": "order.updated",
        "description": "Sent when order is updated. Verify the `BrandGate-Signature` header, then fetch the object for its current state.",
        "parameters": [
          {
            "name": "BrandGate-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1760950000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Event"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Return any 2xx within 10 seconds to acknowledge."
          }
        }
      }
    },
    "invoice.created": {
      "post": {
        "summary": "invoice.created",
        "description": "Sent when invoice is created. Verify the `BrandGate-Signature` header, then fetch the object for its current state.",
        "parameters": [
          {
            "name": "BrandGate-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1760950000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Event"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Return any 2xx within 10 seconds to acknowledge."
          }
        }
      }
    },
    "invoice.updated": {
      "post": {
        "summary": "invoice.updated",
        "description": "Sent when invoice is updated. Verify the `BrandGate-Signature` header, then fetch the object for its current state.",
        "parameters": [
          {
            "name": "BrandGate-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1760950000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Event"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Return any 2xx within 10 seconds to acknowledge."
          }
        }
      }
    },
    "product.stock_low": {
      "post": {
        "summary": "product.stock_low",
        "description": "Sent when product is stock low. Verify the `BrandGate-Signature` header, then fetch the object for its current state.",
        "parameters": [
          {
            "name": "BrandGate-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1760950000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Event"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Return any 2xx within 10 seconds to acknowledge."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "An organization API key (`bg_live_…`), created in BrandGate under Settings → Developers."
      },
      "oauth2": {
        "type": "oauth2",
        "description": "For partner apps acting for many organizations. Authorization code with PKCE (S256).",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.brandgate.dev/oauth/authorize",
            "tokenUrl": "https://api.brandgate.dev/oauth/token",
            "refreshUrl": "https://api.brandgate.dev/oauth/token",
            "scopes": {
              "orders:read": "Read orders and their lines",
              "orders:write": "Acknowledge orders with the ERP's own order number",
              "products:read": "Read products and prices",
              "inventory:read": "Read stock levels",
              "inventory:write": "Update stock levels by SKU",
              "customers:read": "Read customers (resellers), including contact details",
              "invoices:read": "Read invoices",
              "webhooks:read": "List webhook endpoints",
              "webhooks:write": "Create and delete webhook endpoints"
            }
          }
        }
      }
    },
    "headers": {
      "RequestId": {
        "description": "Quote this when contacting support.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "const": "event"
          },
          "type": {
            "type": "string",
            "enum": [
              "order.created",
              "order.updated",
              "invoice.created",
              "invoice.updated",
              "product.stock_low"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "properties": {
              "object": {
                "type": "string",
                "enum": [
                  "order",
                  "invoice",
                  "product"
                ]
              },
              "id": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": [
              "object",
              "id"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "object",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      }
    }
  }
}
