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 queries the AEAT’s VERI*FACTU invoice registry (ConsultaFactuSistemaFacturacion). You can retrieve issued invoices (sales) or received invoices (purchases) filtered by year and month, with optional pagination. Results are returned as RespuestaConsultaFactuSistemaFacturacion objects that can be converted into a list of Invoice instances.

Namespace

VeriFactu.Business.Operations

Constructor

InvoiceQuery(string partyID, string partyName)

Creates a new query context for a specific tax party.
partyID
string
required
The seller’s (or buyer’s) NIF / tax identifier. Used as ObligadoEmision.NIF for sales queries and as Destinatario.NIF for purchase queries.
partyName
string
required
The name corresponding to partyID. Used as ObligadoEmision.NombreRazon or Destinatario.NombreRazon in the SOAP request header.

Propiedades

PartyID
string
The NIF / tax identifier provided at construction.
PartyName
string
The name provided at construction.

Filtros disponibles

Filters are applied by building a ConsultaFactuSistemaFacturacion object with a FiltroConsulta block. The two main query methods (GetSales / GetPurchases) handle the common year + month + pagination pattern. For advanced filtering, use GetRegistro() to obtain a base query object, configure its FiltroConsulta manually, and then call GetDocuments().
FilterSource fieldHow to set
YearFiltroConsulta.PeriodoImputacion.Ejercicioyear parameter on GetSales / GetPurchases
MonthFiltroConsulta.PeriodoImputacion.Periodomonth parameter (zero-padded to 2 digits)
Pagination offsetFiltroConsulta.ClavePaginacionoffset parameter (ClavePaginacion object)
Direction (sales/purchases)Cabecera.ObligadoEmision vs Cabecera.DestinatarioisSales flag on GetRegistro()

Métodos

GetSales(string year, string month, ClavePaginacion offset = null, X509Certificate2 certificate = null)RespuestaConsultaFactuSistemaFacturacion

Queries the AEAT for invoices issued by PartyID in the given year and month.
year
string
required
Four-digit year string, e.g. "2024".
month
string
required
Month as a 1- or 2-digit string (e.g. "1" or "11"). Automatically zero-padded to 2 digits.
offset
ClavePaginacion
Optional pagination key returned in a previous response. When provided, IDEmisorFactura is set to PartyID automatically if it is null.
certificate
X509Certificate2
Optional certificate for the HTTPS request. Falls back to the configured system certificate when omitted.
Returns the raw RespuestaConsultaFactuSistemaFacturacion AEAT response object.
Throws FaultException if the AEAT returns a SOAP Fault.

GetPurchases(string year, string month, ClavePaginacion offset = null, X509Certificate2 certificate = null)RespuestaConsultaFactuSistemaFacturacion

Queries the AEAT for invoices received by PartyID (i.e. where PartyID is the buyer / Destinatario). Parameters and return value are identical to GetSales.

GetDocuments(ConsultaFactuSistemaFacturacion registro, X509Certificate2 certificate = null)RespuestaConsultaFactuSistemaFacturacion

Sends a fully custom ConsultaFactuSistemaFacturacion request. Use this when you need to apply filters beyond year/month (e.g. filter by invoice number, buyer NIF, or invoice type) by constructing the FiltroConsulta block manually.
registro
ConsultaFactuSistemaFacturacion
required
A fully configured VeriFactu.Xml.Factu.Consulta.ConsultaFactuSistemaFacturacion object. Build one from scratch or start from GetRegistro().
certificate
X509Certificate2
Optional certificate for the HTTPS request.

GetRegistro(bool isSales = true)ConsultaFactuSistemaFacturacion

Returns a base ConsultaFactuSistemaFacturacion object pre-populated with the party header. Use this as a starting point for custom queries passed to GetDocuments().
isSales
bool
true (default) places PartyID / PartyName in the ObligadoEmision (issuer / seller) header slot. false places them in Destinatario (recipient / buyer).

GetInvoices(RespuestaConsultaFactuSistemaFacturacion queryAeatResponse)List<Invoice> (static)

Converts a raw AEAT query response into a list of Invoice objects. Each RegistroRespuestaConsultaFactuSistemaFacturacion record is mapped to an Invoice, including type, buyer details, tax breakdown, and rectification information.
queryAeatResponse
RespuestaConsultaFactuSistemaFacturacion
required
A response object returned by GetSales(), GetPurchases(), or GetDocuments().
Throws NotImplementedException if any record in the response has more than one Destinatario (multi-buyer invoices are not yet supported in this conversion helper).

Ejemplo

using VeriFactu.Business;
using VeriFactu.Business.Operations;

// 1. Create query context
var query = new InvoiceQuery("B72877814", "MI EMPRESA SL");

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

// 3. Convert to Invoice objects
var invoices = InvoiceQuery.GetInvoices(response);

Console.WriteLine($"Found {invoices.Count} invoice(s).");
foreach (var inv in invoices)
    Console.WriteLine($"  {inv.InvoiceID}  {inv.InvoiceDate:dd/MM/yyyy}  {inv.TotalAmount:N2} €");

// 4. Paginated query (if the AEAT returned a ClavePaginacion offset)
if (response.ClavePaginacion != null)
{
    var page2 = query.GetSales("2024", "11", offset: response.ClavePaginacion);
    invoices.AddRange(InvoiceQuery.GetInvoices(page2));
}

// 5. Advanced filter: custom registro with additional FiltroConsulta fields
var registro = query.GetRegistro(isSales: true);
registro.FiltroConsulta.NumSerieFactura = "FAC-2024-001"; // filter by invoice number
var singleResult = query.GetDocuments(registro);
The AEAT returns results in pages of up to 500 records. If the response includes a non-null ClavePaginacion, pass it as the offset parameter in a subsequent call to retrieve the next page.

Build docs developers (and LLMs) love