> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usatimbre.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Invoice for Organization

> Create invoice with organization context

## Overview

Create an invoice (factura) from a receipt image within an organization context. This endpoint allows you to specify which member's RFC to use for the invoice.

<Note>
  **This operation requires 1 credit.** Credits are deducted from the organization's balance.
</Note>

## Request Body

<ParamField body="receipt_image" type="string" required>
  Imagen del ticket codificada en Base64. Formatos soportados: JPEG, PNG.
</ParamField>

<ParamField body="cfdi_usage" type="string" required>
  Código de uso CFDI. Valores comunes:

  * `G01` - Adquisición de mercancías
  * `G02` - Devoluciones, descuentos o bonificaciones
  * `G03` - Gastos en general
  * `P01` - Por definir
</ParamField>

<ParamField body="expense_description" type="string">
  Descripción opcional del gasto. Ejemplo: `Compra de equipo`
</ParamField>

<ParamField body="rfc" type="string" required>
  The RFC (Mexican tax ID) of the organization member to generate the invoice for
</ParamField>

## Response

<ResponseField name="id" type="string">
  Unique invoice identifier
</ResponseField>

<ResponseField name="status" type="string">
  Invoice status. Values: `pending`, `processing`, `completed`, `failed`
</ResponseField>

<ResponseField name="amount" type="number">
  Invoice total amount (extracted from receipt)
</ResponseField>

<ResponseField name="currency" type="string">
  Currency code (e.g., `MXN`)
</ResponseField>

<ResponseField name="vendor" type="string">
  Vendor name (extracted from receipt)
</ResponseField>

<ResponseField name="member_rfc" type="string">
  RFC of the member the invoice was generated for
</ResponseField>

<ResponseField name="created_at" type="string">
  ISO 8601 timestamp of creation
</ResponseField>

<ResponseField name="pdf_url" type="string">
  URL to download the invoice PDF (available when status is `completed`)
</ResponseField>

<ResponseField name="xml_url" type="string">
  URL to download the invoice XML/CFDI (available when status is `completed`)
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.usatimbre.com/api/timbre/facturar-ticket-org" \
    -H "Authorization: Bearer tmb_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "receipt_image": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
      "cfdi_usage": "G03",
      "expense_description": "Compra de equipo",
      "rfc": "XAXX010101000"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.usatimbre.com/api/timbre/facturar-ticket-org', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer tmb_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      receipt_image: 'data:image/jpeg;base64,/9j/4AAQSkZJRg...',
      cfdi_usage: 'G03',
      expense_description: 'Compra de equipo',
      rfc: 'XAXX010101000'
    })
  });
  const invoice = await response.json();
  ```

  ```python Python theme={null}
  import requests
  import base64

  # Read and encode image
  with open('receipt.jpg', 'rb') as f:
      image_base64 = base64.b64encode(f.read()).decode('utf-8')

  response = requests.post(
      'https://api.usatimbre.com/api/timbre/facturar-ticket-org',
      headers={
          'Authorization': 'Bearer tmb_your_api_key_here',
          'Content-Type': 'application/json'
      },
      json={
          'receipt_image': f'data:image/jpeg;base64,{image_base64}',
          'cfdi_usage': 'G03',
          'expense_description': 'Compra de equipo',
          'rfc': 'XAXX010101000'
      }
  )
  invoice = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "id": "inv_abc123",
    "status": "processing",
    "amount": null,
    "currency": "MXN",
    "vendor": null,
    "member_rfc": "XAXX010101000",
    "created_at": "2024-01-21T10:30:00Z",
    "pdf_url": null,
    "xml_url": null
  }
  ```

  ```json 400 theme={null}
  {
    "error": "Bad Request",
    "message": "Invalid image format"
  }
  ```

  ```json 402 theme={null}
  {
    "error": "Payment Required",
    "message": "Insufficient credits"
  }
  ```

  ```json 404 theme={null}
  {
    "error": "Not Found",
    "message": "Member with RFC not found in organization"
  }
  ```
</ResponseExample>
