DEV Community

Cover image for Automate Your E-commerce Invoicing with PineBill
Nicat Muzaffarli
Nicat Muzaffarli

Posted on

Automate Your E-commerce Invoicing with PineBill

Running an e-commerce business means dealing with invoices constantly. Every order, subscription renewal, or service delivery needs documentation. Manually creating invoices doesn't scale.

PineBill offers a REST API that lets you automate the entire invoicing workflow. This guide covers the practical integration steps for e-commerce platforms and any application that needs programmatic invoice generation.

What PineBill Offers

PineBill is an invoicing SaaS with 23 API endpoints covering:

  • Invoices: Create, read, update invoices
  • Customers: Full CRUD operations
  • Products: Inventory management with 7 endpoints
  • Categories: Product organization
  • Payment Methods: Transaction processing options
  • Exchange Rates: Multi-currency support

The API follows OpenAPI 3.1 specification, uses Bearer token authentication, and runs on a global CDN with 99.99% uptime.

Getting Started

1. Get Your API Key

Sign up at pinebill.app and navigate to the dashboard. Generate an API key from the API Keys section.

API access is available on:

  • Pro Plan ($29/month): 10,000 API calls/month
  • Enterprise Plan ($90/month): Unlimited API calls

2. Base URL and Authentication

All API requests go to:

https://api.pinebill.app
Enter fullscreen mode Exit fullscreen mode

Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY
Enter fullscreen mode Exit fullscreen mode

Core Integrations for E-commerce

Creating an Invoice Programmatically

When a customer completes a purchase on your platform, trigger an invoice creation:

const createInvoice = async (orderData) => {
  const response = await fetch('https://api.pinebill.app/invoices', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      products: orderData.productIds,
      customerID: orderData.customerId,
      paymentMethods: ['pm_card', 'pm_bank_transfer'],
      invoiceMode: 'PRODUCT',
      taxRate: 10,
      taxType: 'PERCENT',
      issueDate: new Date().toISOString().split('T')[0],
      currency: 'USD'
    })
  });

  return response.json();
};
Enter fullscreen mode Exit fullscreen mode

Syncing Customers from Your Platform

When users register on your e-commerce site, create corresponding customer records in PineBill:

const syncCustomer = async (user) => {
  const response = await fetch('https://api.pinebill.app/customers', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: user.fullName,
      email: user.email,
      phone: user.phone,
      address: user.billingAddress
    })
  });

  const customer = await response.json();
  // Store customer.id in your database for future invoices
  return customer;
};
Enter fullscreen mode Exit fullscreen mode

Managing Products

Keep your product catalog in sync:

// Create a product
const createProduct = async (product) => {
  const response = await fetch('https://api.pinebill.app/products', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: product.name,
      price: product.price,
      description: product.description,
      categoryId: product.categoryId
    })
  });

  return response.json();
};

// Toggle product status (active/inactive)
const toggleProductStatus = async (productId) => {
  await fetch(`https://api.pinebill.app/products/${productId}/toggle-status`, {
    method: 'PATCH',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });
};

// Duplicate a product
const duplicateProduct = async (productId) => {
  const response = await fetch(`https://api.pinebill.app/products/${productId}/duplicate`, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });

  return response.json();
};
Enter fullscreen mode Exit fullscreen mode

Multi-Currency Support

PineBill supports multiple currencies with real-time exchange rates:

const getExchangeRates = async () => {
  const response = await fetch('https://api.pinebill.app/exchange-rates/latest', {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });

  return response.json();
};
Enter fullscreen mode Exit fullscreen mode

Use this when creating invoices for international customers to display amounts in their local currency.

Real-World Integration Patterns

E-commerce Order Webhook Handler

// Express.js webhook handler example
app.post('/webhooks/order-completed', async (req, res) => {
  const order = req.body;

  try {
    // 1. Check if customer exists, create if not
    let customer = await findCustomerByEmail(order.customer.email);
    if (!customer) {
      customer = await syncCustomer(order.customer);
    }

    // 2. Map order items to PineBill product IDs
    const productIds = await mapOrderItemsToProducts(order.items);

    // 3. Create invoice
    const invoice = await createInvoice({
      productIds,
      customerId: customer.id
    });

    // 4. Store invoice reference
    await saveInvoiceReference(order.id, invoice.invoiceNumber);

    res.status(200).json({ success: true, invoiceNumber: invoice.invoiceNumber });
  } catch (error) {
    console.error('Invoice creation failed:', error);
    res.status(500).json({ error: 'Failed to create invoice' });
  }
});
Enter fullscreen mode Exit fullscreen mode

Subscription Platform Integration

For SaaS or subscription businesses, automate recurring invoices:

// Cron job for monthly billing
const processMonthlySubscriptions = async () => {
  const activeSubscriptions = await getActiveSubscriptions();

  for (const subscription of activeSubscriptions) {
    const invoice = await fetch('https://api.pinebill.app/invoices', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        products: [subscription.productId],
        customerID: subscription.customerId,
        invoiceMode: 'PRODUCT',
        taxRate: subscription.taxRate,
        taxType: 'PERCENT',
        issueDate: new Date().toISOString().split('T')[0],
        currency: subscription.currency
      })
    });

    // Send invoice notification to customer
    await notifyCustomer(subscription.email, invoice);
  }
};
Enter fullscreen mode Exit fullscreen mode

Batch Invoice Retrieval

Pull invoice data for reporting or accounting sync:

const getInvoices = async (filters = {}) => {
  const params = new URLSearchParams(filters);

  const response = await fetch(`https://api.pinebill.app/invoices?${params}`, {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });

  return response.json();
};

// Get paid invoices for accounting
const paidInvoices = await getInvoices({ status: 'paid', limit: 100 });
Enter fullscreen mode Exit fullscreen mode

API Endpoint Reference

Endpoint Methods Description
/invoices GET, POST List and create invoices
/invoices/:id GET, PUT Get and update specific invoice
/customers GET, POST List and create customers
/customers/:id GET, PUT, DELETE Manage specific customer
/products GET, POST List and create products
/products/:id GET, PUT, DELETE Manage specific product
/products/:id/toggle-status PATCH Toggle product active status
/products/:id/duplicate POST Duplicate a product
/categories GET, POST List and create categories
/categories/:id GET, PUT, DELETE Manage specific category
/payment-methods GET List available payment methods
/exchange-rates/latest GET Get current exchange rates

Best Practices

Store external IDs: Map your platform's user and product IDs to PineBill customer and product IDs. This prevents duplicate records and speeds up invoice creation.

Validate before creating: Check if customers and products exist before creating invoices. Use GET endpoints to verify records first.

Wrapping Up

PineBill's API gives you everything needed to automate invoicing for e-commerce platforms. The straightforward REST endpoints, multi-currency support, and reasonable pricing (API access starts at $29/month) make it practical for small to mid-sized businesses.

Full API documentation is available at api.pinebill.app/docs.

Start with the 14-day free trial to test your integration before committing to a plan.


Have questions about integrating PineBill? Drop a comment below or check the PineBill API documentation for more details.

Top comments (0)