{
  "openapi": "3.1.0",
  "info": {
    "title": "Settavio Accounting Export API",
    "version": "1.0.0",
    "description": "Read-only source API for ERP connectors. Existing session authentication and organization memberships remain required. No outbound ERP posting is performed. CSV behavior remains available. JSON dates are ISO 8601 and money uses decimal strings. For daily incremental polling use dateBasis=updated, overlapping date windows and stable recordKey/revision deduplication. asOf is a cutoff, not a repeatable-read database snapshot; rows updated during pagination appear in the next polling window. Source records do not determine target ledger, tax or recognition policy."
  },
  "servers": [
    {
      "url": "https://www.settavio.com"
    }
  ],
  "paths": {
    "/api/invoices": {
      "get": {
        "operationId": "getAccountingExport",
        "summary": "Export organization accounting records",
        "security": [
          {
            "ExistingSession": []
          }
        ],
        "parameters": [
          {
            "name": "accountingExport",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "invoices",
                "payments",
                "fees",
                "subscriptions"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "csv",
                "json"
              ],
              "default": "csv"
            }
          },
          {
            "name": "dateBasis",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "record",
                "updated"
              ],
              "default": "record"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "asOf",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "CSV wrapper or paginated versioned JSON records.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/AccountingFeed"
                    },
                    {
                      "$ref": "#/components/schemas/CsvExport"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters or cursor"
          },
          "401": {
            "description": "Existing session required"
          },
          "403": {
            "description": "Organization membership required"
          },
          "413": {
            "description": "Reduce date range or page size"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ExistingSession": {
        "type": "apiKey",
        "in": "header",
        "name": "Cookie",
        "description": "Supply the complete existing authenticated session Cookie header. This does not create API keys or add bearer/OAuth authentication. Connectors must use an authorized existing account and renew its session using the existing login flow."
      }
    },
    "schemas": {
      "AccountingData": {
        "type": "object",
        "required": [
          "record_id",
          "record_date",
          "source_updated_at",
          "currency",
          "status",
          "environment"
        ],
        "properties": {
          "invoice_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "subscription_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "supplier_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "buyer_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "destination_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "client_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "investor_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "settavio_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "destination_org_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "invoice_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "purchase_order_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "payment_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "direction": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider_reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "supplier_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "buyer_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "destination_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "face_value": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "amount": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "invoice_face_value": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "gross_investor_funding": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "invoice_discount": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "fee_rate": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "fee_amount": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "supplier_net_amount": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "base_amount": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "usage_volume": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "usage_amount": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
            "description": "Exact decimal string; never convert through binary floating point for posting."
          },
          "record_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "source_updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "paid_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "settled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "returned_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "reversed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "collected_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "record_id": {
            "type": "string",
            "format": "uuid"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$"
          },
          "status": {
            "type": "string"
          },
          "environment": {
            "type": "string"
          },
          "issue_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "due_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "repayment_days": {
            "type": [
              "integer",
              "null"
            ]
          },
          "bill_number": {
            "type": [
              "integer",
              "null"
            ]
          },
          "invoice_accounting": {
            "type": [
              "object",
              "null"
            ],
            "description": "Source-evidenced invoice accounting detail and completeness findings. Null means this older invoice has not undergone this review. Never treat missing data as zero or complete.",
            "additionalProperties": true
          }
        },
        "additionalProperties": false
      },
      "AccountingRecord": {
        "type": "object",
        "required": [
          "recordKey",
          "revision",
          "data"
        ],
        "properties": {
          "recordKey": {
            "type": "string"
          },
          "revision": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "data": {
            "$ref": "#/components/schemas/AccountingData"
          }
        }
      },
      "AccountingFeed": {
        "type": "object",
        "required": [
          "schemaVersion",
          "organizationId",
          "reportType",
          "asOf",
          "records",
          "hasMore",
          "nextCursor"
        ],
        "properties": {
          "schemaVersion": {
            "const": "1.0.0"
          },
          "source": {
            "type": "string"
          },
          "organizationId": {
            "type": "string",
            "format": "uuid"
          },
          "reportType": {
            "type": "string",
            "enum": [
              "invoices",
              "payments",
              "fees",
              "subscriptions"
            ]
          },
          "dateBasis": {
            "type": "string"
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "asOf": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "generatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "recordCount": {
            "type": "integer"
          },
          "hasMore": {
            "type": "boolean"
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "records": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AccountingRecord"
            }
          },
          "integration": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CsvExport": {
        "type": "object",
        "required": [
          "type",
          "csv",
          "rowCount"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "organizationId": {
            "type": "string"
          },
          "rowCount": {
            "type": "integer"
          },
          "csv": {
            "type": "string"
          }
        }
      }
    }
  }
}
