{
  "openapi": "3.1.0",
  "info": {
    "title": "Ascend vendor API",
    "version": "2026-11-28",
    "description": "Receive rep forms, post vendor-set prices back and report transactions. Human guide: https://app.ascend.inc/docs/reporting/"
  },
  "servers": [{ "url": "https://app.ascend.inc/api/vendor/reporting" }],
  "security": [{ "reportingKey": [] }],
  "paths": {
    "/forms": {
      "get": {
        "summary": "Rep forms waiting for you",
        "description": "Every deal for your products with no sale reported yet, oldest first.",
        "responses": {
          "200": {
            "description": "Pending forms",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "forms": { "type": "array", "items": { "$ref": "#/components/schemas/Form" } } } } } }
          },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/price": {
      "post": {
        "summary": "Send the sale price for a vendor-set deal",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Price" } } } },
        "responses": {
          "200": { "description": "Saved" },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/events": {
      "post": {
        "summary": "Report one transaction",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Event" } } } },
        "responses": {
          "200": { "description": "Duplicate transaction_number, ignored" },
          "202": { "description": "Recorded; the body has the deal's new totals" },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "503": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "reportingKey": { "type": "http", "scheme": "bearer", "description": "Your reporting key (asc_report_...), from the vendor workspace's API keys page." }
    },
    "responses": {
      "Error": {
        "description": "What to fix",
        "content": { "application/json": { "schema": { "type": "object", "required": ["error"], "properties": { "error": { "type": "string" } } } } }
      }
    },
    "schemas": {
      "Event": {
        "type": "object",
        "additionalProperties": false,
        "required": ["product_id", "customer_id", "transaction_number", "transaction_amount_cents"],
        "properties": {
          "product_id": { "type": "string", "format": "uuid", "description": "Ascend Product ID from the form" },
          "customer_id": { "type": "string", "format": "uuid", "description": "Ascend Customer ID from the form" },
          "transaction_number": { "type": "string", "minLength": 1, "maxLength": 160, "description": "Your unique reference; repeats are ignored" },
          "transaction_amount_cents": { "type": "integer", "description": "Amount in cents; negative for a refund" },
          "event_id": { "type": "string", "maxLength": 160, "description": "Name of one of the product's COGS events; omit or \"base\" for the base cost" },
          "cogs_confirmation": {
            "oneOf": [
              { "type": "object", "additionalProperties": false, "required": ["cents"], "properties": { "cents": { "type": "integer" } } },
              { "type": "object", "additionalProperties": false, "required": ["percent"], "properties": { "percent": { "type": "number" } } }
            ],
            "description": "The COGS you applied; replaces the product's COGS terms"
          }
        }
      },
      "Price": {
        "type": "object",
        "additionalProperties": false,
        "required": ["sale_price"],
        "properties": {
          "deal_id": { "type": "string", "format": "uuid" },
          "product_id": { "type": "string", "format": "uuid" },
          "customer_id": { "type": "string", "format": "uuid" },
          "sale_price": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "cents": { "type": "integer", "minimum": 0 },
              "percent": { "type": "number", "minimum": 0, "maximum": 100 },
              "note": { "type": "string", "maxLength": 160 }
            }
          }
        }
      },
      "Form": {
        "type": "object",
        "properties": {
          "deal_id": { "type": "string", "format": "uuid" },
          "product_id": { "type": "string", "format": "uuid" },
          "product": { "type": "string" },
          "customer_id": { "type": "string", "format": "uuid" },
          "customer": {
            "type": "object",
            "properties": {
              "full_name": { "type": "string" },
              "email": { "type": ["string", "null"] },
              "phone": { "type": ["string", "null"] },
              "address": { "type": ["string", "null"] },
              "dob": { "type": ["string", "null"], "format": "date" },
              "customer_type": { "type": ["string", "null"] }
            }
          },
          "pricing_mode": { "enum": ["rep_set", "vendor_set"] },
          "sale_price": { "type": ["object", "null"], "description": "{flat (cents), pct, note}" },
          "answers": { "type": "array", "items": { "type": "object", "properties": { "question": { "type": "string" }, "answer": { "type": "string" } } } },
          "rep": { "type": ["string", "null"] },
          "sent_at": { "type": "string", "format": "date-time" }
        }
      }
    }
  }
}
