Démarrage rapide
Quickstart : créer une facture en Java
Pas de SDK officiel — utiliser HttpClient (Java 11+)
Pas de SDK Java officiel pour Scell.io. Java 11+ inclut `java.net.http.HttpClient` qui suffit pour tous les cas d'usage. Pour les projets Spring Boot, utiliser `RestTemplate` ou `WebClient` (réactif). Pour la sérialisation JSON, Jackson (`com.fasterxml.jackson.databind`) est le standard. Alternative populaire : OkHttp 4.x. La cible idéale est Java 17+ (LTS) ou Java 21+ (LTS). Compatible avec Quarkus, Micronaut, Helidon, et serveurs Jakarta EE.
À retenir
- Prérequis : Java 17+ (LTS), Maven/Gradle
- Pas de SDK officiel : `java.net.http.HttpClient` (stdlib) ou OkHttp
- Variable d'env : `System.getenv("SCELL_API_KEY")`
- HTTP : HttpClient stdlib (zero dépendance)
- Output attendu : `Map<String, Object>` ou DTO Jackson
- Codes erreur : check `response.statusCode()` + parse error JSON
Exemple de code
import java.net.URI;
import java.net.http.*;
import java.util.*;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Quickstart {
static final String API = "https://api.scell.io/api/v1";
static final HttpClient HTTP = HttpClient.newHttpClient();
static final ObjectMapper M = new ObjectMapper();
static Map<String, Object> call(String path, Map<String, Object> body) throws Exception {
String json = M.writeValueAsString(body);
HttpRequest req = HttpRequest.newBuilder(URI.create(API + path))
.header("X-API-Key", System.getenv("SCELL_API_KEY"))
.header("Content-Type", "application/json")
.header("Idempotency-Key", UUID.randomUUID().toString())
.POST(HttpRequest.BodyPublishers.ofString(json)).build();
HttpResponse<String> r = HTTP.send(req, HttpResponse.BodyHandlers.ofString());
if (r.statusCode() >= 400) throw new RuntimeException(r.statusCode() + ": " + r.body());
return M.readValue(r.body(), Map.class);
}
public static void main(String[] args) throws Exception {
var seller = Map.of("siret", "12345678901234", "name", "Ma SAS", "vat_number", "FR12345678901",
"address", Map.of("street", "1 rue Test", "city", "Paris", "postal_code", "75001", "country", "FR"));
var b2b = call("/invoices", Map.of("format", "factur-x", "profile", "EN16931", "currency", "EUR",
"seller", seller,
"buyer", Map.of("siret", "98765432109876", "name", "Client SARL",
"address", Map.of("street", "2 avenue Demo", "city", "Lyon", "postal_code", "69001", "country", "FR")),
"lines", List.of(Map.of("description", "Prestation conseil", "quantity", 1, "unit_price", 1000.0, "vat_rate", 20.0))));
System.out.println("B2B: " + b2b.get("id") + " (" + b2b.get("status") + ")");
var b2c = call("/invoices", Map.of("format", "factur-x", "profile", "EN16931", "currency", "EUR",
"seller", seller,
"buyer", Map.of("buyer_is_individual", true, "name", "Jean Dupont", "email", "jean@example.com",
"address", Map.of("street", "3 bd Client", "city", "Marseille", "postal_code", "13001", "country", "FR")),
"lines", List.of(Map.of("description", "Abonnement", "quantity", 1, "unit_price", 49.90, "vat_rate", 20.0))));
System.out.println("B2C: " + b2c.get("id") + " (" + b2c.get("status") + ")");
var sig = call("/signatures", Map.of("document_url", "https://example.com/contrat.pdf",
"signers", List.of(Map.of("name", "Jean Dupont", "email", "jean@example.com", "phone", "+33612345678")),
"signature_options", Map.of("signature_mode", "drawn", "timezone", "Europe/Paris")));
System.out.println("Signature: " + sig.get("id") + " -> " + sig.get("signing_url"));
}
}