Quickstart
Quickstart: create an invoice in JavaScript
Pure JavaScript (ESM or CJS) with @scell/sdk or fetch
The `@scell/sdk` works in pure JavaScript (no TypeScript) in ESM (`import`) or CJS (`require`) mode. For specific constraints (Cloudflare Workers, Deno, Bun), use native `fetch` directly with the `X-API-Key` header. All payloads are standard snake_case JSON. Node 18+, Bun 1.0+, Deno 1.40+ compatible. Browser-side: use `pk_*` (publishable) only — never `sk_*` (secret).
Key facts
- Requirements: Node.js 18+ / Bun / Deno / Cloudflare Workers
- Install: `npm i @scell/sdk` (with SDK) or nothing (raw fetch)
- Env var: `process.env.SCELL_API_KEY` (Node) / `Deno.env` / `env.SCELL_API_KEY` (CF)
- HTTP: native fetch
- Expected output: JSON object with `id` and `status`
- Error codes: 4xx → throw, 5xx → retry recommended
Code example
// Approche fetch direct (zero-dep). Alternative: import { ScellApiClient } from '@scell/sdk'
const API = 'https://api.scell.io/api/v1';
const KEY = process.env.SCELL_API_KEY;
async function call(path, body) {
const r = await fetch(`${API}${path}`, {
method: 'POST',
headers: { 'X-API-Key': KEY, 'Content-Type': 'application/json', 'Idempotency-Key': crypto.randomUUID() },
body: JSON.stringify(body),
});
if (!r.ok) throw new Error(`${r.status} ${await r.text()}`);
return r.json();
}
const seller = {
siret: '12345678901234', name: 'Ma SAS', vat_number: 'FR12345678901',
address: { street: '1 rue Test', city: 'Paris', postal_code: '75001', country: 'FR' },
};
// 1. Facture B2B
const b2b = await call('/invoices', {
format: 'factur-x', profile: 'EN16931', currency: 'EUR', seller,
buyer: {
siret: '98765432109876', name: 'Client SARL',
address: { street: '2 avenue Demo', city: 'Lyon', postal_code: '69001', country: 'FR' },
},
lines: [{ description: 'Prestation conseil', quantity: 1, unit_price: 1000, vat_rate: 20 }],
});
console.log(`B2B: ${b2b.id} (${b2b.status})`);
// 2. Facture B2C (particulier)
const b2c = await call('/invoices', {
format: 'factur-x', profile: 'EN16931', currency: 'EUR', seller,
buyer: {
buyer_is_individual: true, name: 'Jean Dupont', email: 'jean@example.com',
address: { street: '3 bd Client', city: 'Marseille', postal_code: '13001', country: 'FR' },
},
lines: [{ description: 'Abonnement', quantity: 1, unit_price: 49.9, vat_rate: 20 }],
});
console.log(`B2C: ${b2c.id} (${b2c.status})`);
// 3. Signature simple eIDAS EU-SES
const sig = await call('/signatures', {
document_url: 'https://example.com/contrat.pdf',
signers: [{ name: 'Jean Dupont', email: 'jean@example.com', phone: '+33612345678' }],
signature_options: { signature_mode: 'drawn', timezone: 'Europe/Paris' },
});
console.log(`Signature: ${sig.id} → ${sig.signing_url}`);