Skip to main content

Quickstart

Quickstart: create an invoice in Java

No official SDK — use HttpClient (Java 11+)

No official Java SDK for Scell.io. Java 11+ includes `java.net.http.HttpClient` which covers all use cases. For Spring Boot, use `RestTemplate` or `WebClient` (reactive). For JSON serialization, Jackson (`com.fasterxml.jackson.databind`) is the standard. Popular alternative: OkHttp 4.x. Ideal target is Java 17+ (LTS) or Java 21+ (LTS). Compatible with Quarkus, Micronaut, Helidon, and Jakarta EE servers.

Key facts

  • Requirements: Java 17+ (LTS), Maven/Gradle
  • No official SDK: `java.net.http.HttpClient` (stdlib) or OkHttp
  • Env var: `System.getenv("SCELL_API_KEY")`
  • HTTP: stdlib HttpClient (zero dependency)
  • Expected output: `Map<String, Object>` or Jackson DTO
  • Error codes: check `response.statusCode()` + parse error JSON

Code example

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

See also

Your cookie preferences

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