{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/paidnice-com/json-schema/paidnice-com-invoice-schema.json",
  "title": "Invoice",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/paidnice-com-openapi.json#/components/schemas/Invoice",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Paidnice invoice id. Use it with get_invoice and as invoiceId in list_notes and list_actions. Not the invoice number"
    },
    "accountingSystemId": {
      "type": "string",
      "description": "The invoice's id in the connected accounting system"
    },
    "status": {
      "type": "string",
      "description": "Invoice status in the accounting system, for example AUTHORISED or PAID"
    },
    "number": {
      "type": "string",
      "description": "Invoice number shown to the customer"
    },
    "reference": {
      "type": "string",
      "description": "The invoice reference from the accounting system, often a purchase order number"
    },
    "currency": {
      "type": "string",
      "description": "Invoice currency (ISO 4217 code). The amounts are in this currency"
    },
    "frozen": {
      "type": "boolean",
      "description": "True when Paidnice is skipping the invoice, so its policies do not run on it"
    },
    "sentToCustomer": {
      "type": "boolean",
      "description": "True when the invoice has been sent to the customer"
    },
    "dueAmount": {
      "type": "number",
      "description": "Amount still owed, as a decimal in the invoice currency"
    },
    "totalAmount": {
      "type": "number",
      "description": "Invoice total including tax, as a decimal in the invoice currency"
    },
    "subtotalAmount": {
      "type": "number",
      "description": "Invoice total before tax, as a decimal in the invoice currency"
    },
    "taxAmount": {
      "type": "number",
      "description": "Tax on the invoice, as a decimal in the invoice currency"
    },
    "paidAmount": {
      "type": "number",
      "description": "Amount paid so far, as a decimal in the invoice currency"
    },
    "discountAmount": {
      "type": "number",
      "description": "Total discount applied to the invoice, as a decimal in the invoice currency"
    },
    "creditedAmount": {
      "type": "number",
      "description": "Total credited against the invoice, as a decimal in the invoice currency"
    },
    "depositAmount": {
      "type": "number",
      "description": "Deposit amount, as a decimal in the invoice currency. QuickBooks Online only, 0 otherwise"
    },
    "exchangeRate": {
      "type": "number",
      "description": "Exchange rate Paidnice uses for the invoice, 1 when the invoice is in the base currency"
    },
    "accountingSystemExchangeRate": {
      "type": "number",
      "description": "Exchange rate recorded on the invoice in the accounting system, when it has one"
    },
    "issueDate": {
      "type": "string",
      "description": "Date the invoice was issued, as YYYY-MM-DD"
    },
    "dueDate": {
      "type": "string",
      "description": "Date the invoice is due, as YYYY-MM-DD"
    },
    "lastSyncedDate": {
      "type": "string",
      "description": "When Paidnice last synced a change to the invoice from the accounting system, as an ISO 8601 datetime"
    },
    "portalUrl": {
      "type": "string",
      "description": "Link to the invoice in the Paidnice customer payment portal"
    },
    "accountingSystemOnlineUrl": {
      "type": "string",
      "description": "Link to view the invoice online in the accounting system, when available"
    },
    "contactId": {
      "type": "integer",
      "description": "Paidnice id of the invoice's contact. Use it with get_contact"
    },
    "contactName": {
      "type": "string",
      "description": "Name of the invoice's contact"
    },
    "assignedUser": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "Paidnice user id. Pass it as userId to update_invoice_assignee or update_contact_assignee"
        },
        "email": {
          "type": "string",
          "description": "The team member's email address"
        },
        "firstName": {
          "type": "string",
          "description": "First name, when set"
        },
        "lastName": {
          "type": "string",
          "description": "Last name, when set"
        }
      },
      "required": [
        "id",
        "email"
      ],
      "description": "The team member who owns the invoice, null when unassigned"
    },
    "paymentPromises": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/PaymentPromise"
      },
      "description": "Promises to pay on the invoice, newest first. Only present with includePaymentPromises"
    },
    "invoiceQueries": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/InvoiceQuery"
      },
      "description": "Queries on the invoice, newest first. Only present with includeInvoiceQueries"
    },
    "paymentPlans": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/PaymentPlan"
      },
      "description": "Payment plans on the invoice, newest first. Only present with includePaymentPlans"
    }
  },
  "required": [
    "id",
    "accountingSystemId",
    "status",
    "currency",
    "frozen",
    "sentToCustomer",
    "dueAmount",
    "totalAmount",
    "subtotalAmount",
    "taxAmount",
    "paidAmount",
    "discountAmount",
    "creditedAmount",
    "depositAmount",
    "exchangeRate",
    "issueDate",
    "dueDate",
    "portalUrl",
    "contactId",
    "assignedUser"
  ],
  "$defs": {
    "InvoiceQuery": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "description": "Paidnice invoice query id"
        },
        "invoiceId": {
          "type": "string",
          "description": "Id of the queried invoice, as used by get_invoice"
        },
        "contactId": {
          "type": "integer",
          "description": "Id of the contact who raised it, as used by get_contact"
        },
        "status": {
          "type": "string",
          "enum": [
            "open",
            "resolved"
          ],
          "description": "open until the team resolves it"
        },
        "reason": {
          "type": "string",
          "enum": [
            "pricing",
            "quantity",
            "quality",
            "not_received",
            "duplicate",
            "other"
          ],
          "description": "Why the customer queried the invoice"
        },
        "detail": {
          "type": "string",
          "description": "What the customer said, required when reason is other"
        },
        "nextAction": {
          "type": "string",
          "description": "What the team plans to do next"
        },
        "dueDate": {
          "type": "string",
          "description": "YYYY-MM-DD in the organisation's timezone, when the next action is due"
        },
        "source": {
          "type": "string",
          "enum": [
            "user",
            "portal",
            "ai_agent",
            "escalation",
            "call"
          ],
          "description": "Where the query was raised"
        },
        "resolution": {
          "type": "string",
          "enum": [
            "paid",
            "credit_note",
            "voided",
            "withdrawn",
            "written_off"
          ],
          "description": "How it was resolved, once resolved"
        },
        "createdAt": {
          "type": "string",
          "description": "When the query was raised"
        },
        "resolvedAt": {
          "type": "string",
          "description": "When it was resolved"
        }
      },
      "required": [
        "id",
        "invoiceId",
        "contactId",
        "status",
        "reason",
        "source",
        "createdAt"
      ]
    },
    "PaymentPlan": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "description": "Paidnice payment plan id"
        },
        "invoiceId": {
          "type": "string",
          "description": "Id of the invoice the plan pays off, as used by get_invoice"
        },
        "contactId": {
          "type": "integer",
          "description": "Id of the contact on the plan, as used by get_contact"
        },
        "status": {
          "type": "string",
          "enum": [
            "active",
            "completed"
          ],
          "description": "active while any instalment is not fully paid, completed once all are"
        },
        "originalDueAmount": {
          "type": "number",
          "description": "The invoice amount due when the plan was set up, in the invoice currency"
        },
        "surchargeAmount": {
          "type": "number",
          "description": "Fee added to the invoice for the plan, if any"
        },
        "createdAt": {
          "type": "string",
          "description": "When the plan was set up"
        },
        "instalments": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer",
                "description": "Paidnice instalment id"
              },
              "amount": {
                "type": "number",
                "description": "Amount due for this instalment"
              },
              "paidAmount": {
                "type": "number",
                "description": "Amount paid towards this instalment so far"
              },
              "dueDate": {
                "type": "string",
                "description": "YYYY-MM-DD the instalment is due"
              },
              "paidDate": {
                "type": "string",
                "description": "YYYY-MM-DD a payment was first applied to it"
              }
            },
            "required": [
              "id",
              "amount",
              "paidAmount",
              "dueDate"
            ]
          },
          "description": "In due date order. Amounts are in the invoice currency"
        }
      },
      "required": [
        "id",
        "invoiceId",
        "contactId",
        "status",
        "originalDueAmount",
        "createdAt",
        "instalments"
      ]
    },
    "PaymentPromise": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "description": "Paidnice promise to pay id"
        },
        "invoiceId": {
          "type": "string",
          "description": "Id of the invoice it is for, as used by get_invoice"
        },
        "contactId": {
          "type": "integer",
          "description": "Id of the contact who made it, as used by get_contact"
        },
        "status": {
          "type": "string",
          "enum": [
            "open",
            "kept",
            "broken",
            "cancelled"
          ],
          "description": "open until the promised date passes or the invoice is paid, then kept or broken. cancelled when withdrawn"
        },
        "promisedAmount": {
          "type": "number",
          "description": "In the invoice currency"
        },
        "promisedDate": {
          "type": "string",
          "description": "YYYY-MM-DD in the organisation's timezone"
        },
        "notes": {
          "type": "string",
          "description": "Internal notes recorded with the promise. Never shown to the customer"
        },
        "source": {
          "type": "string",
          "enum": [
            "user",
            "portal",
            "escalation",
            "call",
            "ai_agent"
          ],
          "description": "Where the promise was recorded"
        },
        "createdAt": {
          "type": "string",
          "description": "When the promise was recorded"
        },
        "resolvedAt": {
          "type": "string",
          "description": "When it became kept, broken or cancelled"
        }
      },
      "required": [
        "id",
        "invoiceId",
        "contactId",
        "status",
        "promisedAmount",
        "promisedDate",
        "source",
        "createdAt"
      ]
    }
  }
}