{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/codeqr-io/json-schema/codeqr-io-sale-event-schema.json",
  "title": "SaleEvent",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/codeqr-io-openapi.yml#/components/schemas/SaleEvent",
  "type": "object",
  "properties": {
    "event": {
      "type": "string",
      "enum": [
        "sale"
      ]
    },
    "timestamp": {
      "type": "string"
    },
    "eventId": {
      "type": "string"
    },
    "eventName": {
      "type": "string"
    },
    "link": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The unique ID of the short link."
        },
        "domain": {
          "type": "string",
          "description": "The domain of the short link. If not provided, the main domain of the project will be used (or `codeqr.link` if the project has no domains)."
        },
        "key": {
          "type": "string",
          "description": "The slug of the short link. If not provided, a random 7-character slug will be generated."
        },
        "url": {
          "type": "string"
        },
        "archived": {
          "type": "boolean"
        },
        "expiresAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "expiredUrl": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri",
          "default": null
        },
        "trackConversion": {
          "type": "boolean"
        },
        "flexible": {
          "type": "boolean",
          "default": false,
          "description": "Whether the short link is flexible."
        },
        "doIndex": {
          "type": "boolean"
        },
        "password": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "externalId": {
          "type": [
            "string",
            "null"
          ]
        },
        "proxy": {
          "type": "boolean"
        },
        "title": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "image": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "video": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "rewrite": {
          "type": "boolean"
        },
        "ios": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "android": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "geo": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {
            "type": "string"
          },
          "default": null
        },
        "rules": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "properties": {
              "attribute": {
                "type": "string",
                "enum": [
                  "device",
                  "country",
                  "utm_source",
                  "utm_medium",
                  "utm_campaign",
                  "referrer",
                  "language",
                  "city",
                  "region",
                  "continent",
                  "utm_term",
                  "utm_content"
                ]
              },
              "operator": {
                "type": "string",
                "enum": [
                  "equals",
                  "not_equals"
                ]
              },
              "value": {
                "type": "string"
              },
              "url": {
                "type": "string"
              }
            },
            "required": [
              "attribute",
              "operator",
              "value",
              "url"
            ]
          }
        },
        "publicStats": {
          "type": "boolean"
        },
        "tagId": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "tags": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "$ref": "#/$defs/TagSchema"
          },
          "default": null
        },
        "folderId": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "comments": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "notificationToken": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "shortLink": {
          "type": "string",
          "format": "uri",
          "description": "The complete URL of the short link, including the https protocol (for example, `https://codeqr.link/try`)."
        },
        "qrCode": {
          "type": "string",
          "format": "uri",
          "description": "The complete QR code URL for the short link (for example, `https://api.codeqr.io/qr?url=https://codeqr.link/try`)."
        },
        "utm_source": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "utm_medium": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "utm_campaign": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "utm_term": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "utm_content": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "userId": {
          "type": [
            "string",
            "null"
          ]
        },
        "projectId": {
          "type": "string",
          "description": "The ID of the project of the short link."
        },
        "clicks": {
          "type": "number",
          "default": 0,
          "description": "The number of clicks on the short link."
        },
        "leads": {
          "type": "number",
          "default": 0,
          "description": "The number of leads generated by the short link."
        },
        "sales": {
          "type": "number",
          "default": 0,
          "description": "The number of sales generated by the short link."
        },
        "saleAmount": {
          "type": "number",
          "default": 0,
          "description": "The amount of the sale generated by the link."
        },
        "lastClicked": {
          "nullable": true,
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "string"
            }
          ]
        },
        "createdAt": {
          "type": "string"
        },
        "updatedAt": {
          "type": "string"
        },
        "preRedirection": {
          "type": "boolean",
          "default": false,
          "description": "Whether the short link has pre-redirection."
        },
        "pageId": {
          "type": [
            "string",
            "null"
          ],
          "description": "The ID of the page to redirect to before the link destination."
        },
        "pageUrl": {
          "type": [
            "string",
            "null"
          ],
          "description": "The URL of the page to redirect to before the link destination."
        },
        "isFormMandatory": {
          "type": "boolean",
          "default": false,
          "description": "If the form is mandatory for the page."
        },
        "filled": {
          "type": "boolean",
          "default": false,
          "description": "Whether the link is filled or not."
        },
        "useAsTemplate": {
          "type": "boolean",
          "default": false,
          "description": "Whether this link should be used as a reusable template."
        }
      },
      "required": [
        "id",
        "domain",
        "key",
        "expiredUrl",
        "flexible",
        "password",
        "title",
        "description",
        "image",
        "video",
        "ios",
        "android",
        "geo",
        "tagId",
        "tags",
        "folderId",
        "comments",
        "notificationToken",
        "utm_source",
        "utm_medium",
        "utm_campaign",
        "utm_term",
        "utm_content",
        "projectId",
        "clicks",
        "leads",
        "sales",
        "saleAmount",
        "createdAt",
        "updatedAt",
        "preRedirection",
        "isFormMandatory",
        "filled",
        "useAsTemplate"
      ]
    },
    "click": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "continent": {
          "type": "string"
        },
        "country": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "device": {
          "type": "string"
        },
        "browser": {
          "type": "string"
        },
        "os": {
          "type": "string"
        },
        "referer": {
          "type": "string"
        },
        "refererUrl": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "ip": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "url",
        "continent",
        "country",
        "city",
        "device",
        "browser",
        "os",
        "referer",
        "refererUrl",
        "type",
        "ip"
      ]
    },
    "customer": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The unique ID of the customer. You may use either the customer's `id` on CodeQR (obtained via `/customers` endpoint) or their `externalId` (unique ID within your system, prefixed with `ext_`, e.g. `ext_123`)."
        },
        "externalId": {
          "type": "string",
          "description": "Unique identifier for the customer in the client's app."
        },
        "name": {
          "type": "string",
          "description": "Name of the customer."
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "description": "Email of the customer."
        },
        "avatar": {
          "type": [
            "string",
            "null"
          ],
          "description": "Avatar URL of the customer."
        },
        "country": {
          "type": [
            "string",
            "null"
          ],
          "description": "Country of the customer."
        },
        "createdAt": {
          "type": "string",
          "description": "The date the customer was created."
        },
        "link": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "id": {
              "type": "string",
              "description": "The unique ID of the short link."
            },
            "domain": {
              "type": "string",
              "description": "The domain of the short link. If not provided, the main domain of the project will be used (or `codeqr.link` if the project has no domains)."
            },
            "key": {
              "type": "string",
              "description": "The slug of the short link. If not provided, a random 7-character slug will be generated."
            },
            "shortLink": {
              "type": "string",
              "format": "uri",
              "description": "The complete URL of the short link, including the https protocol (for example, `https://codeqr.link/try`)."
            }
          },
          "required": [
            "id",
            "domain",
            "key"
          ]
        },
        "customFields": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {
            "type": "string"
          },
          "description": "Custom fields of the customer."
        }
      },
      "required": [
        "id",
        "externalId",
        "name",
        "createdAt"
      ]
    },
    "sale": {
      "type": "object",
      "properties": {
        "amount": {
          "type": "integer",
          "minimum": 0,
          "description": "The amount of the sale in the smallest unit of `currency` — cents for two-decimal currencies, the full integer for zero-decimal ones (e.g. `1437` JPY), thousandths for three-decimal ones (e.g. `1437` KWD fils)."
        },
        "invoiceId": {
          "type": [
            "string",
            "null"
          ],
          "default": null,
          "description": "The invoice ID of the sale. Can be used as a idempotency key – only one sale event can be recorded for a given invoice ID."
        },
        "paymentProcessor": {
          "type": "string",
          "enum": [
            "stripe",
            "shopify",
            "polar",
            "paddle",
            "revenuecat",
            "custom",
            "manual"
          ],
          "default": "custom",
          "description": "The payment processor via which the sale was made."
        }
      },
      "required": [
        "amount",
        "invoiceId",
        "paymentProcessor"
      ]
    },
    "saleAmount": {
      "type": "number",
      "description": "Deprecated. Use `sale.amount` instead.",
      "deprecated": true
    },
    "invoice_id": {
      "type": "string",
      "description": "Deprecated. Use `sale.invoiceId` instead.",
      "deprecated": true
    },
    "payment_processor": {
      "type": "string",
      "description": "Deprecated. Use `sale.paymentProcessor` instead."
    },
    "metadata": {
      "type": "string"
    },
    "click_id": {
      "type": "string",
      "description": "Deprecated. Use `click.id` instead.",
      "deprecated": true
    },
    "link_id": {
      "type": "string",
      "description": "Deprecated. Use `link.id` instead.",
      "deprecated": true
    },
    "domain": {
      "type": "string",
      "description": "Deprecated. Use `link.domain` instead.",
      "deprecated": true
    },
    "key": {
      "type": "string",
      "description": "Deprecated. Use `link.key` instead.",
      "deprecated": true
    },
    "url": {
      "type": "string",
      "description": "Deprecated. Use `click.url` instead.",
      "deprecated": true
    },
    "continent": {
      "type": "string",
      "description": "Deprecated. Use `click.continent` instead.",
      "deprecated": true
    },
    "country": {
      "type": "string",
      "description": "Deprecated. Use `click.country` instead.",
      "deprecated": true
    },
    "city": {
      "type": "string",
      "description": "Deprecated. Use `click.city` instead.",
      "deprecated": true
    },
    "device": {
      "type": "string",
      "description": "Deprecated. Use `click.device` instead.",
      "deprecated": true
    },
    "browser": {
      "type": "string",
      "description": "Deprecated. Use `click.browser` instead.",
      "deprecated": true
    },
    "os": {
      "type": "string",
      "description": "Deprecated. Use `click.os` instead.",
      "deprecated": true
    },
    "type": {
      "type": "string",
      "description": "Deprecated. Use `click.qr` instead.",
      "deprecated": true
    },
    "ip": {
      "type": "string",
      "description": "Deprecated. Use `click.ip` instead.",
      "deprecated": true
    }
  },
  "required": [
    "event",
    "eventId",
    "eventName",
    "link",
    "click",
    "customer",
    "sale",
    "saleAmount",
    "invoice_id",
    "payment_processor",
    "metadata",
    "click_id",
    "link_id",
    "domain",
    "key",
    "url",
    "continent",
    "country",
    "city",
    "device",
    "browser",
    "os",
    "type",
    "ip"
  ],
  "$defs": {
    "TagSchema": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The unique ID of the tag."
        },
        "name": {
          "type": "string",
          "description": "The name of the tag."
        },
        "color": {
          "type": "string",
          "enum": [
            "red",
            "yellow",
            "green",
            "blue",
            "purple",
            "pink",
            "brown"
          ],
          "description": "The color of the tag."
        }
      },
      "required": [
        "id",
        "name",
        "color"
      ],
      "title": "Tag"
    }
  }
}