> API Documentation

Complete API reference for JSONBill - create PDF invoices and settlement statements from JSON data

Table of Contents

Overview

JSONBill is a super lightweight JSON-based billing system. It provides a RESTful API for creating PDF invoices and settlement statements from JSON data.

Related: x402 Payments

Authentication

All API endpoints require authentication via the Authorization header:

Authorization: Bearer <token>

The <token> can be either a JWT token or an API key. The system automatically detects the token type.

Credits

Each PDF generation costs 1 Quaily credit. When using API key authentication, your credit balance is checked before task creation. Ensure you have sufficient credits in your account.

x402 Payments (v2)

JSONBill supports x402 v2 for pay-per-request onchain payments. Supported network/asset: Base (eip155:8453) USDC.

When paying with x402, you do not need the Authorization header. Detailed guide: x402 Payments.

Flow:

  1. Call POST /tasks/docs without PAYMENT-SIGNATURE.
  2. Receive 402 Payment Required with a PAYMENT-REQUIRED header (base64 PaymentRequired JSON).
  3. Sign the payment using an x402 client and retry with PAYMENT-SIGNATURE.

Retry example (headers only):

Content-Type: application/json
PAYMENT-SIGNATURE: <base64 payment payload>

API Endpoints

Create Document Task

Endpoint: POST /tasks/docs

Description: Create a new PDF invoice or settlement statement generation task from JSON data.

Request Headers:

Content-Type: application/json
Authorization: Bearer <token>

Request Body Example:

{
  "type": "invoice",
  "lang": "en",
  "theme": "classic",
  "params": {
    "id": "20260102-INC-1",
    "date": "2026-01-02T09:30:01.001Z",
    "currency": "USD",
    "company_name": "Example Inc.",
    "company_address": "No.102, Roodwood St., Pasadena, CA, 98812",
    "company_email": "john@example.com",
    "tax_number": "123456789Z",
    "bill_to_company": "Hello Inc.",
    "bill_to_address": "2F House, AZ Church St, George, 119802",
    "doc": {
      "title": "Invoice",
      "description": "Consulting services for Dec 2025"
    },
    "summary": {
      "period_start": "2025-12-01T00:00:00.000Z",
      "period_end": "2026-01-01T00:00:00.000Z",
      "title": "Consulting Service",
      "currency": "USD",
      "total_include_tax": 10000,
      "tax_rate": 0.08,
      "total_include_tax_quote_amount": 1500000,
      "total_include_tax_quote_symbol": "JPY"
    },
    "detail_items": [
      {
        "date": "2025-12-15T00:00:00.000Z",
        "title": "Project Alpha - Phase 1",
        "desc": "Initial development and setup",
        "currency": "USD",
        "total_include_tax": 5000,
        "total_include_tax_quote_amount": 750000,
        "total_include_tax_quote_symbol": "JPY"
      },
      {
        "date": "2025-12-28T00:00:00.000Z",
        "title": "Project Alpha - Phase 2",
        "desc": "Testing and deployment",
        "url": "https://example.com/project-alpha",
        "total_include_tax": 5000
      }
    ],
    "payment": {
      "instruction": {
        "receive_account_bank": "Bank of George",
        "receive_account_branch": "Roodwood St. Branch",
        "receive_account_number": "12345-113",
        "receive_deposit_type": "Checking",
        "receive_account_name": "Example Inc"
      }
    }
  }
}

Request Parameters:

ParameterTypeRequiredDescription
typestringNoDocument type: invoice or settlementstatement. Default: invoice
langstringNoLanguage code (en, ja, zh_cn, zh_tw). Default: en
themestringNoDocument theme. Default: classic
paramsobjectYesDocument data (see Document Data Format)

Settlement statement notes:

  • Use recipient_company / recipient_address instead of bill_to_company / bill_to_address.
  • payment.instruction is ignored; only payment.result is rendered.

Available Themes:

ThemeDescription
classicTraditional invoice layout, matches the baseline output
modernDashboard style with two-column layout for bill-to and summary sections
compactDenser version of modern, reduced whitespace, more one-page friendly
spotlightBig total/payment amount upfront, then details - good for quick scanning
ledgerAccounting style with details first, totals and summary at the end
splitDetails first, then two-column footer with payment and summary side by side

Preview the PDF output for each theme: Theme Samples.

Response:

{
  "data": {
    "id": 1,
    "trace_id": "f4730554-791c-463b-9a27-aeacdfb02cf2",
    "status": 0,
    "created_at": "2026-01-02T09:30:01.001Z",
    "updated_at": "2026-01-02T09:30:01.001Z"
  },
  "ts": 1767766187
}

Task Status Codes:

  • 0: Init (task created)
  • 1: Scheduled
  • 2: Running
  • 3: Completed
  • 4: Error

Query Task Status

Endpoint: GET /tasks/{traceID}

Description: Check the status of a document generation task.

Response:

{
  "data": {
    "id": 1,
    "trace_id": "f4730554-791c-463b-9a27-aeacdfb02cf2",
    "status": 3,
    "created_at": "2026-01-02T09:30:01.001Z",
    "updated_at": "2026-01-02T09:30:05.001Z"
  },
  "ts": 1767766191
}

Download PDF

Endpoint: GET /tasks/{traceID}.pdf

Description: Download the generated PDF document. Only available when task status is 3 (Completed).

Response: PDF file

Note: The PDF file will be removed from the server after 1 hour.

Check Credit Balance

Endpoint: GET /proxy/credits/balance

Description: Check your current credit balance.

Response:

{
  "data": {
    "user_id": 123,
    "balance_credit": "10.00",
    "status": 1
  },
  "ts": 1767766187
}

Document Data Format

Basic Document Fields

FieldTypeRequiredDescription
idstringNoDocument ID/number
datestringNoDocument date (ISO 8601 format)
currencystringNoCurrency code (e.g., USD, EUR, JPY, CNY). Supports any currency code.
company_namestringYesYour company name
company_addressstringNoYour company address
company_emailstringNoYour company email
tax_numberstringNoTax registration number
bill_to_companystringNoClient company name (invoice only)
bill_to_addressstringNoClient address (invoice only)
recipient_companystringNoRecipient company name (settlement statement)
recipient_addressstringNoRecipient address (settlement statement)
docobjectNoDocument info (see Document Fields)

Document Fields

The doc object controls the document title and description shown on the document:

FieldTypeRequiredDescription
titlestringNoDocument title
descriptionstringNoDocument description

Summary Fields

The summary object contains the document totals and period information:

FieldTypeRequiredDescription
titlestringNoSummary title/description
period_startstringNoBilling period start date (ISO 8601)
period_endstringNoBilling period end date (ISO 8601)
currencystringNoCurrency code for this summary (defaults to top-level currency)
total_exclude_taxnumberNoTotal amount excluding tax
total_include_taxnumberNoTotal amount including tax
taxnumberNoTax amount
tax_ratenumberNoTax rate (e.g., 0.08 for 8%)
total_include_tax_quote_amountnumberNoEquivalent amount in quote currency
total_include_tax_quote_symbolstringNoQuote currency symbol (e.g., JPY)

Notes:

  • total_exclude_tax and total_include_tax are mutually exclusive.
  • When using total_exclude_tax, provide either tax or tax_rate.

Quote Currency Example:

When invoicing in USD but your client prefers to see the amount in their local currency:

"summary": {
  "total_include_tax": 10000,
  "total_include_tax_quote_amount": 1500000,
  "total_include_tax_quote_symbol": "JPY"
}

This displays an implied exchange rate of 1 USD = 150 JPY on the document.

Excluding Tax Example:

"summary": {
  "total_exclude_tax": 9259.26,
  "tax": 740.74
}

Detail Items

The detail_items array contains line items for the document:

FieldTypeRequiredDescription
datestringNoItem date (ISO 8601)
titlestringNoItem title
descstringNoItem description
urlstringNoRelated URL
currencystringNoCurrency code for this item (defaults to top-level currency)
total_exclude_taxnumberNoItem amount excluding tax
total_include_taxnumberNoItem amount including tax
total_include_tax_quote_amountnumberNoEquivalent amount in quote currency (item-level)
total_include_tax_quote_symbolstringNoQuote currency symbol (item-level)
taxnumberNoItem tax amount

Notes:

  • total_exclude_tax and total_include_tax are mutually exclusive.
  • When using total_exclude_tax, you can provide tax.

Example:

"detail_items": [
  {
    "date": "2025-12-15T00:00:00.000Z",
    "title": "Consulting - Week 1",
    "desc": "Strategy planning and analysis",
    "total_exclude_tax": 2500,
    "tax": 200
  },
  {
    "date": "2025-12-22T00:00:00.000Z",
    "title": "Consulting - Week 2",
    "desc": "Implementation support",
    "url": "https://example.com/report",
    "total_exclude_tax": 2500,
    "tax": 200
  }
]

Payment Methods

The payment object has two optional sections:

  • instruction: how your client should pay.
  • result: payment outcome (optional).

Both sections support a disabled flag to hide them on the document.

Bank Transfer (Instruction)

"payment": {
  "instruction": {
    "receive_account_bank": "Bank of George",
    "receive_account_branch": "Roodwood St. Branch",
    "receive_account_number": "12345-113",
    "receive_deposit_type": "Checking",
    "receive_account_name": "Example Inc"
  }
}

SWIFT Transfer (Instruction)

"payment": {
  "instruction": {
    "receive_account_swift": "BOFAUS3N",
    "receive_account_number": "123456789",
    "receive_account_name": "Example Inc.",
    "receive_account_bank": "Bank of America",
    "receive_account_branch": "Charlotte, NC"
  }
}

Cryptocurrency (Instruction)

"payment": {
  "instruction": {
    "receive_crypto_network": "ETH Mainnet",
    "receive_crypto_address": "0x1234567890abcdef1234567890abcdef12345678",
    "receive_crypto_currency": "USDC",
    "receive_crypto_memo": ""
  }
}
FieldDescription
instruction.receive_crypto_networkBlockchain network (e.g., ETH Mainnet, Polygon, Solana)
instruction.receive_crypto_addressWallet address to receive payment
instruction.receive_crypto_currencyCryptocurrency symbol (e.g., USDC, USDT, ETH)
instruction.receive_crypto_memoOptional memo or destination tag (for networks like XRP, XLM)

Payment Result (Optional)

"payment": {
  "result": {
    "payment_method": "Bank transfer",
    "amount_paid": 5200,
    "currency": "USD",
    "paid_date": "2026-01-27",
    "tx_id": "TXN-12345"
  }
}
FieldDescription
result.payment_methodMethod used to pay (free text)
result.amount_paidAmount actually paid
result.currencyCurrency for the paid amount
result.paid_datePayment date (ISO string)
result.tx_idTransaction or reference ID