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");
    }
}

The content provided by Bilbabit SL in any of its sections (Blog, guides, landing pages, FAQ section, commercial or customer support emails) is for informational purposes only and has no legal validity. BILBABIT is not a tax consulting firm, but a fiscal software developer, so the information it provides is of an indicative nature. In any case, any activity related to invoicing and taxation should always and without exception be consulted with a tax advisor who understands the specific implications of each regulation for each company or professional in particular.