Complying with Verifactu in C#: developer guide

Help for developers to integrate Verifactu with C#: learn to make REST requests, generate invoices with QR, sign with digital certificate and create XML efficiently.

screenshot
Verifacti

Verifacti

Mar 18, 2025

How to make a request to a REST API from C#

To make HTTP requests in C#, you can use several libraries, including:

Request example with HttpClient:

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace VerifactiApiCall
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var apiKey = "<API_KEY>";
            var url = "https://api.verifacti.com/verifactu/create";
            var json = @"{
  ""serie"": ""A"",
  ""numero"": ""234634"",
  ""fecha_expedicion"": ""02-12-2024"",
  ""tipo_factura"": ""F1"",
  ""descripcion"": ""Descripcion de la operacion"",
  ""nif"": ""A15022510"",
  ""nombre"": ""Nombre cliente"",
  ""lineas"": [{
    ""base_imponible"": ""200"",
    ""tipo_impositivo"": ""21"",
    ""cuota_repercutida"": ""42""
  }],
  ""importe_total"": ""242""
}";
            
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
                var content = new StringContent(json, Encoding.UTF8, "application/json");
                var response = await client.PostAsync(url, content);
                var responseString = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseString);
            }
        }
    }
}

How to attach the QR to the invoice in C#

To embed a QR code in a PDF, you can use libraries such as:

Example with iTextSharp:

using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

class Program
{
    static void Main()
    {
        Document doc = new Document();
        PdfWriter.GetInstance(doc, new FileStream("FacturaConQR.pdf", FileMode.Create));
        doc.Open();

        Image qrImage = Image.GetInstance("QRFactura.png");
        doc.Add(qrImage);

        doc.Close();
    }
}

How to generate a QR in C#

To generate QR codes in C#, you can use libraries such as:

Example with QRCoder:

using QRCoder;
using System.Drawing;

class Program
{
    static void Main()
    {
        QRCodeGenerator qrGenerator = new QRCodeGenerator();
        QRCodeData qrCodeData = qrGenerator.CreateQrCode("https://verifacti.com", QRCodeGenerator.ECCLevel.Q);
        QRCode qrCode = new QRCode(qrCodeData);
        Bitmap qrCodeImage = qrCode.GetGraphic(20);
        qrCodeImage.Save("QRFactura.png");
    }
}

Related posts

Verifactu Visual Basic: Complying with Verifactu regulations

Help for developers to integrate Verifactu with Visual Basic: learn to make REST requests, generate invoices with QR, sign with digital certificate and create XML efficiently.

Verifactu mandatory compliance: who must comply with Verifactu?

Verifactu mandatory compliance. Who is required to comply with VeriFactu. Mandatory compliance for computerized invoicing systems, legal entities and self-employed workers.

Over 25 Verifactu invoice examples: complete guide for developers

Complete collection of Verifactu invoice examples: simplified, standard, corrective, intra-Community, export, IGIC, IPSI, cancellation, and more. Ready-to-copy JSON.