Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/mdiago/VeriFactu/llms.txt

Use this file to discover all available pages before exploring further.

InvoiceQuery lets you query the AEAT’s VERI*FACTU registry to retrieve invoice records for a given NIF/tax ID. This is useful for reconciliation, auditing, or verifying that records were correctly registered. The class wraps the AEAT’s ConsultaFactuSistemaFacturacion SOAP operation and returns responses as typed RespuestaConsultaFactuSistemaFacturacion objects, which can then be converted into Invoice business objects.
La consulta se realiza contra el entorno de pruebas de la AEAT por defecto. Para apuntar al entorno de producción, configure Settings.Current.VeriFactuEndPointPrefix con el prefijo del endpoint de producción antes de ejecutar cualquier consulta.

Constructor

var query = new InvoiceQuery(string partyID, string partyName);
ParámetroTipoDescripción
partyIDstringNIF del obligado tributario (vendedor) sobre el que ejecutar la consulta.
partyNamestringNombre o razón social correspondiente al NIF.
var query = new InvoiceQuery("B72877814", "WEFINZ GANDIA SL");

Consulta de facturas emitidas (ventas)

Use GetSales(year, month) to retrieve issued invoices for a given year and month. Both parameters are strings.
var query = new InvoiceQuery("B72877814", "WEFINZ GANDIA SL");

// Query issued invoices for November 2024
var response = query.GetSales("2024", "11");

// Convert the AEAT response records into Invoice business objects
var invoices = InvoiceQuery.GetInvoices(response);

foreach (var invoice in invoices)
{
    Console.WriteLine($"{invoice.SellerID} | {invoice.InvoiceID} | {invoice.InvoiceDate:dd-MM-yyyy} | {invoice.TotalAmount:F2}");
}

Consulta de facturas recibidas (compras)

Use GetPurchases(year, month) to query invoices received by the party (as buyer):
var query = new InvoiceQuery("B72877814", "WEFINZ GANDIA SL");

var response = query.GetPurchases("2024", "11");
var invoices = InvoiceQuery.GetInvoices(response);

foreach (var invoice in invoices)
{
    Console.WriteLine($"Factura recibida: {invoice.InvoiceID} de {invoice.SellerID}");
}

Filtros disponibles

Both GetSales and GetPurchases accept the period as year/month strings. For more advanced filtering — such as by specific invoice number or with a custom ConsultaFactuSistemaFacturacion filter object — use GetDocuments() and build the query manually via GetRegistro():
var query = new InvoiceQuery("B72877814", "WEFINZ GANDIA SL");

// Get the base query object and customise its filter
var registro = query.GetRegistro(isSales: true);

// Filter by period
registro.FiltroConsulta.PeriodoImputacion = new PeriodoImputacion()
{
    Ejercicio = "2024",
    Periodo = "11"     // Month is zero-padded automatically by the helper methods
};

// Execute the custom query
var response = query.GetDocuments(registro);
var invoices = InvoiceQuery.GetInvoices(response);

Paginación

The AEAT returns results in pages. When a response contains more records than the page size, use ClavePaginacion as the offset parameter on subsequent calls to retrieve the next page.
var query = new InvoiceQuery("B72877814", "WEFINZ GANDIA SL");

ClavePaginacion offset = null;
var allInvoices = new List<Invoice>();

do
{
    var response = query.GetSales("2024", "11", offset);
    var page = InvoiceQuery.GetInvoices(response);
    allInvoices.AddRange(page);

    // The AEAT response includes the pagination key for the next page,
    // if one exists. Set offset to null when no further pages remain.
    offset = response.ClavePaginacion;

} while (offset != null);

Console.WriteLine($"Total facturas recuperadas: {allInvoices.Count}");
The offset parameter on GetSales and GetPurchases accepts a ClavePaginacion object. When offset.IDEmisorFactura is null, the library automatically sets it to PartyID before sending the request.

Convertir respuesta en objetos Invoice

InvoiceQuery.GetInvoices() is a static helper that converts a RespuestaConsultaFactuSistemaFacturacion into a List<Invoice>:
// Static helper — works with any response object
List<Invoice> invoices = InvoiceQuery.GetInvoices(response);
Each returned Invoice is populated with:
  • InvoiceID, InvoiceDate, SellerID
  • InvoiceType, RectificationType
  • BuyerID, BuyerName (if present in the response)
  • TaxItems (converted from Desglose)
  • Calculated totals (TotalAmount, TotalTaxOutput, etc.)

Uso del certificado

All query methods accept an optional X509Certificate2 certificate parameter. If omitted, the certificate configured in Settings.Current is used automatically.
var cert = new X509Certificate2(@"C:\CERTIFICADO.pfx", "password");

var response = query.GetSales("2024", "11", certificate: cert);

Build docs developers (and LLMs) love