Invoice Generator API Documentation

This API allows you to generate invoices and PDF documents programmatically. See a live embedding example | Get embed code for your website

Authentication

Currently, the API is open and does not require authentication. In a production environment, you should implement API keys or OAuth.

API Endpoints

GET /api/status

Check if the API is running.

Example Response:
{
  "status": "success",
  "message": "Invoice Generator API is running",
  "version": "1.0.0"
}
GET /api/generate-invoice-number

Generate a unique invoice number.

Example Response:
{
  "status": "success",
  "invoice_number": "INV-2025-A1B2C3"
}
POST /api/create-invoice

Create a new invoice with the provided data.

Request Body:
{
  "company_name": "Your Company",
  "company_address": "123 Business Street, City, Country",
  "customer_name": "Client Name",
  "customer_address": "456 Client Avenue, City, Country",
  "customer_email": "client@example.com",
  "invoice_number": "INV-2025-123456",  // Optional, will be generated if not provided
  "invoice_date": "2025-04-19",         // Optional, defaults to today
  "due_date": "2025-05-19",             // Optional
  "tax_rate": "0",                      // Optional, defaults to 0
  "currency": "USD",                    // Optional, defaults to USD
  "notes": "Thank you for your business!",
  "items": [
    {
      "description": "Web Design Services",
      "quantity": 1,
      "unit_price": 1000
    },
    {
      "description": "Hosting (Monthly)",
      "quantity": 12,
      "unit_price": 20
    }
  ]
}
Example Response:
{
  "status": "success",
  "message": "Invoice generated successfully",
  "invoice": {
    "company_name": "Your Company",
    "company_address": "123 Business Street, City, Country",
    "customer_name": "Client Name",
    "customer_email": "client@example.com",
    "customer_address": "456 Client Avenue, City, Country",
    "invoice_number": "INV-2025-123456",
    "invoice_date": "2025-04-19",
    "due_date": "2025-05-19",
    "line_items": [
      {
        "description": "Web Design Services",
        "quantity": 1,
        "unit_price": 1000,
        "total": 1000
      },
      {
        "description": "Hosting (Monthly)",
        "quantity": 12,
        "unit_price": 20,
        "total": 240
      }
    ],
    "notes": "Thank you for your business!",
    "currency": "USD",
    "subtotal": 1240,
    "tax_rate": 0,
    "tax_amount": 0,
    "grand_total": 1240
  }
}
POST /api/pdf-invoice

Generate a PDF invoice file from the provided data.

This endpoint accepts the same JSON format as the create-invoice endpoint and returns a PDF file.

Integration Examples

HTML & JavaScript Example
<!-- Include this in your HTML -->
<button id="createInvoice">Generate Invoice</button>

<script>
document.getElementById('createInvoice').addEventListener('click', async () => {
  const invoiceData = {
    company_name: "Your Company",
    company_address: "123 Business Street, City, Country",
    customer_name: "Client Name",
    customer_address: "456 Client Avenue, City, Country",
    customer_email: "client@example.com",
    tax_rate: "0",
    currency: "USD",
    items: [
      {
        description: "Web Design Services",
        quantity: 1,
        unit_price: 1000
      }
    ]
  };

  try {
    const response = await fetch('https://invoicemedley.com/api/create-invoice', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(invoiceData)
    });
    
    const result = await response.json();
    
    if (result.status === 'success') {
      console.log('Invoice created:', result.invoice);
      
      // To download the PDF version
      window.open('https://invoicemedley.com/api/pdf-invoice', '_blank');
    } else {
      console.error('Error:', result.message);
    }
  } catch (error) {
    console.error('Error:', error);
  }
});
</script>
Python Example
import requests
import json

# API endpoint
api_url = "https://invoicemedley.com/api/create-invoice"

# Invoice data
invoice_data = {
    "company_name": "Your Company",
    "company_address": "123 Business Street, City, Country",
    "customer_name": "Client Name",
    "customer_address": "456 Client Avenue, City, Country",
    "customer_email": "client@example.com",
    "tax_rate": "0",
    "currency": "USD",
    "items": [
        {
            "description": "Web Design Services",
            "quantity": 1,
            "unit_price": 1000
        }
    ]
}

# Make the API request
response = requests.post(
    api_url,
    headers={"Content-Type": "application/json"},
    data=json.dumps(invoice_data)
)

# Process the response
if response.status_code == 200:
    result = response.json()
    print("Invoice created successfully!")
    print(f"Invoice number: {result['invoice']['invoice_number']}")
    print(f"Total amount: {result['invoice']['grand_total']}")
else:
    print(f"Error: {response.status_code}")
    print(response.text)
Note: For production use, make sure to implement proper authentication and rate limiting.