DELETE
/
invoices
/
{id}
curl -X DELETE https://api.contazen.ro/v1/invoices/inv_abc123 \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"
{
  "success": true,
  "data": {
    "object": "invoice",
    "id": "inv_abc123",
    "deleted": true,
    "deleted_at": "2024-01-15T14:35:00+00:00"
  },
  "meta": {
    "version": "v1",
    "response_time": "23.45ms"
  }
}

Overview

Permanently removes an invoice from the database. This is an irreversible action - deleted invoices cannot be recovered and will return 404 errors on all API calls.

Understanding Invoice States

StateDatabase StatusAPI VisibilityCan Delete?
ActiveRecord existsFully visibleNo - must void first
VoidedRecord exists with cancelled flagVisible with status: "voided"Yes - if last in series
DeletedRecord removedReturns 404N/A - already gone

Deletion Rules

Invoices can only be deleted if they are:
  1. Draft invoices - Can always be deleted
  2. Voided invoices - Can be deleted only if:
    • They are the last invoice in their series (for sequential numbering)
    • No newer invoices exist with the same series

Workflow for Deleting Fiscal Invoices

Active Invoice → Void → Delete (if last in series)
Sequential Numbering Requirement: Romanian fiscal regulations require invoice numbers to be sequential with no gaps. A voided invoice can only be deleted if it’s the last in the series to prevent numbering gaps.
Permanent Action: Deletion completely removes the invoice from the database. This action cannot be undone. For audit trail purposes, consider keeping invoices as voided instead of deleting them.

Path Parameters

id
string
required
The invoice ID to delete

Response

success
boolean
Indicates if the request was successful
data
object
Confirmation of deletion
message
string
Success message confirming deletion
meta
object
Response metadata
curl -X DELETE https://api.contazen.ro/v1/invoices/inv_abc123 \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"
{
  "success": true,
  "data": {
    "object": "invoice",
    "id": "inv_abc123",
    "deleted": true,
    "deleted_at": "2024-01-15T14:35:00+00:00"
  },
  "meta": {
    "version": "v1",
    "response_time": "23.45ms"
  }
}

Important Notes

Deletion Process

  • Invoices are marked with is_deleted = 1 in the database
  • Deleted invoices return “404 Not Found” when accessed via API
  • Deleted invoices are excluded from list endpoints
  • Deletion cannot be reversed
  • The invoice data is retained in the database for audit and compliance purposes but is inaccessible via API

Compliance Requirements

Romanian fiscal regulations require:
  • Numbered invoices must be voided before deletion
  • Invoice numbers must remain sequential - you can only delete the last invoice in a series
  • Audit trail must be maintained for all fiscal documents
  • Deleted invoices are kept for the legally required retention period

Sequential Numbering Rule

To maintain fiscal compliance with sequential invoice numbering:
  • When deleting a voided invoice with a number, the system checks if it’s the last in its series
  • If newer invoices exist in the same series, deletion is blocked
  • This prevents gaps in the middle of the invoice number sequence
  • Draft invoices (without numbers) can be deleted at any time

What Gets Deleted

When an invoice is deleted:
  • The invoice record is marked as deleted
  • Associated invoice lines are marked as deleted
  • Payment records remain for accounting integrity
  • E-Factura submissions (if any) are retained for compliance

Common Use Cases

Delete a Draft Invoice

// Delete draft invoice that was never finalized
const response = await fetch('https://api.contazen.ro/v1/invoices/inv_draft123', {
  method: 'DELETE',
  headers: {
    'Authorization': 'Bearer sk_live_YOUR_API_KEY'
  }
});

if (response.ok) {
  console.log('Draft invoice deleted');
}

Delete After Voiding (Last in Series)

// Step 1: Void the fiscal invoice
const voidResponse = await fetch('https://api.contazen.ro/v1/invoices/inv_abc123/void', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_live_YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    reason: 'Duplicate invoice'
  })
});

// Step 2: Delete the voided invoice (only works if it's the last in series)
if (voidResponse.ok) {
  const deleteResponse = await fetch('https://api.contazen.ro/v1/invoices/inv_abc123', {
    method: 'DELETE',
    headers: {
      'Authorization': 'Bearer sk_live_YOUR_API_KEY'
    }
  });
  
  if (deleteResponse.ok) {
    console.log('Voided invoice deleted successfully');
  } else {
    const error = await deleteResponse.json();
    if (error.error.code === 'invoice_not_last_in_series') {
      console.log('Cannot delete - newer invoices exist in this series');
    }
  }
}

Check Series Before Deletion

// Example: Delete the last voided invoice in a series
async function deleteLastVoidedInvoice(seriesId) {
  // Get all invoices in the series
  const invoices = await fetch(`https://api.contazen.ro/v1/invoices?series_id=${seriesId}&sort=number&order=desc`, {
    headers: { 'Authorization': 'Bearer sk_live_YOUR_API_KEY' }
  });
  
  const data = await invoices.json();
  
  // Check if the last invoice is voided
  const lastInvoice = data.data[0];
  if (lastInvoice && lastInvoice.status === 'voided') {
    // Safe to delete - it's the last in the series
    const deleteResponse = await fetch(`https://api.contazen.ro/v1/invoices/${lastInvoice.id}`, {
      method: 'DELETE',
      headers: { 'Authorization': 'Bearer sk_live_YOUR_API_KEY' }
    });
    
    if (deleteResponse.ok) {
      console.log(`Deleted last voided invoice: ${lastInvoice.invoice_number}`);
      return true;
    }
  }
  
  console.log('Cannot delete - invoice is not voided or not last in series');
  return false;
}

Error Handling

async function deleteInvoice(invoiceId) {
  try {
    const response = await fetch(`https://api.contazen.ro/v1/invoices/${invoiceId}`, {
      method: 'DELETE',
      headers: {
        'Authorization': 'Bearer sk_live_YOUR_API_KEY'
      }
    });
    
    const result = await response.json();
    
    if (!response.ok) {
      if (result.error.code === 'invoice_not_deletable') {
        // Invoice needs to be voided first
        console.log('Invoice must be voided first');
        // Optionally trigger void process
      } else if (response.status === 404) {
        console.log('Invoice not found or already deleted');
      } else {
        console.error('Delete failed:', result.error.message);
      }
      return false;
    }
    
    console.log('Invoice deleted:', result.data.id);
    return true;
    
  } catch (error) {
    console.error('Request failed:', error);
    return false;
  }
}
Deletion is permanent. Consider using the void endpoint if you need to cancel an invoice while maintaining a complete audit trail.