TildeAfip.Sdk 0.1.1

dotnet add package TildeAfip.Sdk --version 0.1.1
                    
NuGet\Install-Package TildeAfip.Sdk -Version 0.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TildeAfip.Sdk" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TildeAfip.Sdk" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="TildeAfip.Sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TildeAfip.Sdk --version 0.1.1
                    
#r "nuget: TildeAfip.Sdk, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TildeAfip.Sdk@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TildeAfip.Sdk&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=TildeAfip.Sdk&version=0.1.1
                    
Install as a Cake Tool

TildeAfip.Sdk

Cliente HTTP tipado para integrar con la API de Tilde — plataforma de facturación electrónica AFIP (Argentina). Pensado para consumirse desde apps .NET 8+ (ASP.NET Core, Worker Service, Azure Functions, MAUI server-side, etc.).

Instalación

dotnet add package TildeAfip.Sdk

Esto trae TildeAfip.Contracts (los DTOs) como dependencia transitiva.

Setup mínimo

using TildeAfip.Sdk;
using TildeAfip.Sdk.DependencyInjection;

builder.Services.AddTildeAfipClient(options =>
{
    options.BaseAddress = new Uri("https://api.tilde.example.com");
    options.ApiKey = builder.Configuration["TildeAfip:ApiKey"]; // de Key Vault / User Secrets
    options.DefaultTenantId = Guid.Parse(builder.Configuration["TildeAfip:TenantId"]!);
});

Y desde tu servicio:

public sealed class FacturacionService(ITildeInvoicingClient tilde)
{
    public async Task<Guid> EmitirAsync(IssueInvoiceRequest request, CancellationToken ct)
    {
        var idempotencyKey = Guid.NewGuid().ToString(); // único por intento
        var invoice = await tilde.IssueAsync(request, idempotencyKey, ct: ct);
        return invoice.Id;
    }
}

Qué resuelve el SDK por vos

  • HttpClient factory + lifetime management — sin sockets colgados.
  • Headers obligatorios — X-Tenant-Id, Idempotency-Key, X-Correlation-Id, X-Api-Key armados automáticamente.
  • Resiliencia — retries con backoff exponencial + jitter sobre 5xx/red (Microsoft.Extensions.Http.Resilience).
  • Errores tipados — 4xx/5xx tiran TildeApiException con StatusCode, ErrorCode y ResponseBody.
  • Idempotencia — ya tipada en la firma; no podés olvidarte de pasar la key.
  • Serialización compatible con el server — camelCase + enums como strings.

Ejemplo: emisión Factura B

var request = new IssueInvoiceRequest(
    CustomerId: Guid.Parse("33333333-3333-3333-3333-333333333333"),
    PointOfSale: 1,
    Kind: InvoiceKind.FacturaB,
    InvoiceDate: DateOnly.FromDateTime(DateTime.Today),
    Lines: new[]
    {
        new IssueInvoiceRequestLine(
            Description: "Servicio de consultoría",
            Quantity: 1m,
            UnitPrice: 100_000m,
            VatRateAfipCode: (int)IvaRateAfipCode.Rate21),
    });

try
{
    var invoice = await tilde.IssueAsync(request, Guid.NewGuid().ToString(), ct: ct);
    Console.WriteLine($"CAE: {invoice.Cae}, vencimiento: {invoice.CaeExpirationDate}");
}
catch (TildeApiException ex) when (ex.StatusCode == HttpStatusCode.UnprocessableEntity)
{
    // 422 = AFIP rechazó (CUIT inválido, monto fuera de rango, etc.) — error de negocio
    logger.LogWarning("AFIP rechazó la factura: {Code} {Message}", ex.ErrorCode, ex.Message);
}

Ejemplo: generación del PDF firmado

public sealed class DocumentService(ITildeDocumentsClient docs)
{
    public async Task<string> GetPdfUrlAsync(InvoiceDetailResponse invoice, CancellationToken ct)
    {
        var request = new GenerateInvoiceDocumentRequest(
            InvoiceId: invoice.Id,
            InvoiceKind: invoice.Kind,
            PointOfSale: invoice.PointOfSale,
            InvoiceNumber: invoice.Number!.Value,
            InvoiceDate: DateOnly.FromDateTime(invoice.CreatedAt.Date),
            Issuer: new PartyDto("20111111119", TaxIdKind.Cuit, "Mi Empresa SRL", IvaCondition.ResponsableInscripto, null),
            Receiver: new PartyDto(invoice.ReceiverDocNumber, TaxIdKind.Dni, "Cliente Final", IvaCondition.ConsumidorFinal, null),
            Lines: invoice.Items.Select(i => new DocumentLineDto(
                i.Description, i.Quantity, i.UnitPrice, 21m, i.TotalAmount / 1.21m, i.TotalAmount - (i.TotalAmount / 1.21m), i.TotalAmount)).ToList(),
            Totals: new TotalsDto(invoice.NetAmount, invoice.IvaAmount, invoice.TotalAmount, invoice.Currency),
            Cae: new CaeInfoDto(invoice.Cae!, invoice.CaeExpirationDate!.Value));

        var result = await docs.GenerateInvoicePdfAsync(request, ct: ct);
        return result.AccessUrl;
    }
}

Configuración avanzada

Property Default Descripción
BaseAddress — (requerido) Host de Tilde. Ej: https://api.tilde.example.com.
DocumentsBaseAddress null Override si Documents está en otro host.
ApiKey null Se manda como X-Api-Key. Cargar desde Key Vault / User Secrets.
DefaultTenantId null X-Tenant-Id por default. Override por llamada con tenantId: named arg.
Timeout 30s Timeout del HttpClient.

Servicios cubiertos (v0.1)

  • Invoicing — POST /api/invoices, GET /api/invoices/{id}, GET /api/invoices, POST /api/invoices/batch.
  • Documents — POST /api/documents/invoice (generación PDF firmado).

Próximas versiones: Notifications (webhooks subscription), TenantManagement (admin), AfipGateway (queries directas al ARCA).

Compatibilidad

Multi-target net8.0 + net9.0 + net10.0. Cualquier consumer en .NET 8 LTS o superior puede usarlo.

Licencia

MIT. Ver LICENSE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 296 6/1/2026
0.1.0 138 5/29/2026