{
  "openapi": "3.1.0",
  "info": {
    "title": "BusyNotify BUSY Accounting Software API",
    "version": "1.0.0",
    "description": "REST API surface for accessing BUSY Accounting Software data through BusyNotify integrations. Endpoint availability depends on the customer's enabled modules and approved data scope.",
    "contact": {
      "name": "BusyNotify",
      "url": "https://busynotify.in/contact"
    }
  },
  "servers": [
    {
      "url": "https://api.busynotify.in",
      "description": "Production API"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Customers",
      "description": "BUSY Accounting Software party and customer data"
    },
    {
      "name": "Invoices",
      "description": "BUSY invoice and bill data"
    },
    {
      "name": "Products",
      "description": "BUSY item master and stock data"
    },
    {
      "name": "Ledgers",
      "description": "BUSY ledger statements and balances"
    }
  ],
  "paths": {
    "/v1/customers": {
      "get": {
        "tags": ["Customers"],
        "summary": "List BUSY customers",
        "description": "Returns customer or party master records from BUSY Accounting Software.",
        "parameters": [
          {
            "name": "updated_after",
            "in": "query",
            "schema": { "type": "string", "format": "date-time" },
            "description": "Return records updated after this timestamp."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "maximum": 500, "default": 100 }
          }
        ],
        "responses": {
          "200": {
            "description": "Customer list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Customer" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/bills": {
      "get": {
        "tags": ["Invoices"],
        "summary": "List BUSY bills and invoices",
        "description": "Returns invoice and bill data from BUSY Accounting Software with payment status and line items when enabled.",
        "parameters": [
          {
            "name": "customer_id",
            "in": "query",
            "schema": { "type": "string" }
          },
          {
            "name": "from",
            "in": "query",
            "schema": { "type": "string", "format": "date" }
          },
          {
            "name": "to",
            "in": "query",
            "schema": { "type": "string", "format": "date" }
          }
        ],
        "responses": {
          "200": {
            "description": "Bill list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Bill" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/products": {
      "get": {
        "tags": ["Products"],
        "summary": "List BUSY products",
        "description": "Returns item master, price, HSN, unit, and stock information from BUSY Accounting Software.",
        "responses": {
          "200": {
            "description": "Product list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Product" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/ledgers/{ledger_id}": {
      "get": {
        "tags": ["Ledgers"],
        "summary": "Get BUSY ledger statement",
        "description": "Returns a ledger statement and current balance for a BUSY Accounting Software ledger.",
        "parameters": [
          {
            "name": "ledger_id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "from",
            "in": "query",
            "schema": { "type": "string", "format": "date" }
          },
          {
            "name": "to",
            "in": "query",
            "schema": { "type": "string", "format": "date" }
          }
        ],
        "responses": {
          "200": {
            "description": "Ledger statement",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LedgerStatement" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Customer": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "phone": { "type": "string" },
          "email": { "type": "string" },
          "gstin": { "type": "string" },
          "city": { "type": "string" },
          "state": { "type": "string" },
          "balance": { "type": "number" },
          "credit_limit": { "type": "number" }
        }
      },
      "Bill": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "invoice_number": { "type": "string" },
          "customer_id": { "type": "string" },
          "date": { "type": "string", "format": "date" },
          "due_date": { "type": "string", "format": "date" },
          "amount": { "type": "number" },
          "balance_due": { "type": "number" },
          "status": { "type": "string", "enum": ["paid", "partially_paid", "unpaid"] }
        }
      },
      "Product": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "sku": { "type": "string" },
          "hsn": { "type": "string" },
          "unit": { "type": "string" },
          "stock": { "type": "number" },
          "price": { "type": "number" }
        }
      },
      "LedgerStatement": {
        "type": "object",
        "properties": {
          "ledger_id": { "type": "string" },
          "ledger_name": { "type": "string" },
          "opening_balance": { "type": "number" },
          "closing_balance": { "type": "number" },
          "transactions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": { "type": "string", "format": "date" },
                "voucher_type": { "type": "string" },
                "voucher_number": { "type": "string" },
                "debit": { "type": "number" },
                "credit": { "type": "number" },
                "narration": { "type": "string" }
              }
            }
          }
        }
      }
    }
  }
}
