Démarrage rapide
Quickstart : créer une facture en C#
Pas de SDK officiel — utiliser HttpClient + System.Text.Json
Pas de SDK C# officiel pour Scell.io. .NET 6+ (LTS) inclut `HttpClient` et `System.Text.Json`, suffisants pour tous les cas. Pour ASP.NET Core, injecter `IHttpClientFactory` (best practice). Pour les retries, utiliser Polly (`Microsoft.Extensions.Http.Polly`). Le mapping JSON snake_case ↔ PascalCase se gère via `JsonPropertyName` ou `JsonNamingPolicy.SnakeCaseLower` (.NET 8+). Compatible Blazor, MAUI, Worker Services, Azure Functions.
À retenir
- Prérequis : .NET 8+ (LTS recommandé)
- Pas de SDK officiel : `HttpClient` + `System.Text.Json` (stdlib)
- Variable d'env : `Environment.GetEnvironmentVariable("SCELL_API_KEY")`
- HTTP : `HttpClient` (singleton via `IHttpClientFactory` en ASP.NET)
- Output attendu : `JsonDocument` ou DTO record
- Codes erreur : `response.EnsureSuccessStatusCode()` + try/catch `HttpRequestException`
Exemple de code
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")}");