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

# Subida de facturas

> Sube facturas de suministros y calcula automáticamente huella de carbono, hídrica y de residuos

Manglai permite subir facturas de suministros (electricidad, gas, agua, combustibles, residuos…) y calcular automáticamente la huella ambiental asociada mediante IA. El proceso es simple: subes el archivo y la plataforma extrae los datos y genera los consumos correspondientes.

## ¿Qué calcula Manglai?

A partir de una factura, Manglai calcula:

* **Huella de carbono** — emisiones de CO₂e por consumo energético o de combustibles
* **Huella hídrica** — consumo y estrés hídrico asociado
* **Gestión de residuos** — impacto ambiental por tipo y método de tratamiento

## Subir una factura con escaneo IA

`POST /api/v1/invoices/upload-invoice`

Este endpoint acepta un archivo en `multipart/form-data`. La IA de Manglai extrae automáticamente el proveedor, periodo, consumo y coste.

```bash theme={null}
curl -X POST "https://www.manglai.io/api/v1/invoices/upload-invoice" \
  -H "Authorization: Bearer TU_TOKEN_AQUI" \
  -F "companyId=1b1e07a7-083d-4831-a1d2-84b6e93a1572" \
  -F "file=@factura-electricidad-enero-2024.pdf"
```

### Respuesta

```json theme={null}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "type": "electricity",
  "companyId": "1b1e07a7-083d-4831-a1d2-84b6e93a1572",
  "startDate": "2024-01-01T00:00:00.000Z",
  "endDate": "2024-01-31T23:59:59.999Z",
  "totalCost": 1240.50,
  "currency": "EUR",
  "status": "scanned",
  "emissions": {
    "co2e": 342.8,
    "unit": "kg"
  }
}
```

## Crear una factura manualmente

Si prefieres introducir los datos directamente sin escaneo, usa `POST /api/v1/invoices`:

```bash theme={null}
curl -X POST "https://www.manglai.io/api/v1/invoices" \
  -H "Authorization: Bearer TU_TOKEN_AQUI" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "type": "electricity",
    "companyId": "1b1e07a7-083d-4831-a1d2-84b6e93a1572",
    "totalCost": 1240.50,
    "currency": "EUR",
    "startDate": "2024-01-01T00:00:00.000Z",
    "endDate": "2024-01-31T23:59:59.999Z"
  }'
```

### Campos requeridos

| Campo       | Tipo     | Descripción                                                                  |
| ----------- | -------- | ---------------------------------------------------------------------------- |
| `id`        | `uuid`   | Identificador único de la factura (generado por ti)                          |
| `type`      | `string` | Tipo de factura: `electricity`, `heat`, `fuel`, `water`, `wastes`, `others`… |
| `companyId` | `uuid`   | ID de la empresa a la que pertenece la factura                               |
| `totalCost` | `number` | Coste total de la factura                                                    |
| `currency`  | `string` | Moneda: `EUR`, `USD`, etc.                                                   |
| `startDate` | `date`   | Inicio del periodo de consumo                                                |
| `endDate`   | `date`   | Fin del periodo de consumo                                                   |

<Note>
  Para facturas de tipo `wastes`, también son necesarios `wasteType` y `wasteDisposalMethod`.
</Note>

## Listar facturas

`GET /api/v1/invoices`

```bash theme={null}
curl -X GET "https://www.manglai.io/api/v1/invoices?companyId=1b1e07a7-083d-4831-a1d2-84b6e93a1572" \
  -H "Authorization: Bearer TU_TOKEN_AQUI"
```

## Más información

* [Referencia completa del endpoint Invoices →](/api-reference)
* [Autenticación →](/authentication)
