Skip to main content

Quickstart

Quickstart: create an invoice in C#

No official SDK — use HttpClient + System.Text.Json

No official C# SDK for Scell.io. .NET 6+ (LTS) includes `HttpClient` and `System.Text.Json`, sufficient for all cases. For ASP.NET Core, inject `IHttpClientFactory` (best practice). For retries, use Polly (`Microsoft.Extensions.Http.Polly`). JSON snake_case ↔ PascalCase mapping is handled via `JsonPropertyName` or `JsonNamingPolicy.SnakeCaseLower` (.NET 8+). Compatible with Blazor, MAUI, Worker Services, Azure Functions.

Key facts

  • Requirements: .NET 8+ (LTS recommended)
  • No official SDK: `HttpClient` + `System.Text.Json` (stdlib)
  • Env var: `Environment.GetEnvironmentVariable("SCELL_API_KEY")`
  • HTTP: `HttpClient` (singleton via `IHttpClientFactory` in ASP.NET)
  • Expected output: `JsonDocument` or DTO record
  • Error codes: `response.EnsureSuccessStatusCode()` + try/catch `HttpRequestException`

Code example

using System.Net.Http.Json;
using System.Text.Json;

var http = new HttpClient { BaseAddress = new Uri("https://api.scell.io/api/v1/") };
http.DefaultRequestHeaders.Add("X-API-Key", Environment.GetEnvironmentVariable("SCELL_API_KEY"));

async Task<JsonElement> Call(string path, object body) {
    var req = new HttpRequestMessage(HttpMethod.Post, path) { Content = JsonContent.Create(body) };
    req.Headers.Add("Idempotency-Key", Guid.NewGuid().ToString());
    var r = await http.SendAsync(req);
    var json = await r.Content.ReadAsStringAsync();
    if (!r.IsSuccessStatusCode) throw new Exception($"{(int)r.StatusCode}: {json}");
    return JsonDocument.Parse(json).RootElement;
}

var seller = new {
    siret = "12345678901234", name = "Ma SAS", vat_number = "FR12345678901",
    address = new { street = "1 rue Test", city = "Paris", postal_code = "75001", country = "FR" }
};

var b2b = await Call("invoices", new {
    format = "factur-x", profile = "EN16931", currency = "EUR", seller,
    buyer = new {
        siret = "98765432109876", name = "Client SARL",
        address = new { street = "2 avenue Demo", city = "Lyon", postal_code = "69001", country = "FR" }
    },
    lines = new[] { new { description = "Prestation conseil", quantity = 1, unit_price = 1000.0, vat_rate = 20.0 } }
});
Console.WriteLine($"B2B: {b2b.GetProperty("id")} ({b2b.GetProperty("status")})");

var b2c = await Call("invoices", new {
    format = "factur-x", profile = "EN16931", currency = "EUR", seller,
    buyer = new {
        buyer_is_individual = true, name = "Jean Dupont", email = "jean@example.com",
        address = new { street = "3 bd Client", city = "Marseille", postal_code = "13001", country = "FR" }
    },
    lines = new[] { new { description = "Abonnement", quantity = 1, unit_price = 49.90, vat_rate = 20.0 } }
});
Console.WriteLine($"B2C: {b2c.GetProperty("id")} ({b2c.GetProperty("status")})");

var sig = await Call("signatures", new {
    document_url = "https://example.com/contrat.pdf",
    signers = new[] { new { name = "Jean Dupont", email = "jean@example.com", phone = "+33612345678" } },
    signature_options = new { signature_mode = "drawn", timezone = "Europe/Paris" }
});
Console.WriteLine($"Signature: {sig.GetProperty("id")} -> {sig.GetProperty("signing_url")}");

See also

Your cookie preferences

We use cookies to improve your experience. Essential cookies are always active. Cookie policy.