SDK TypeScript
TiimeClient
Client principal — initialisation, options et exemples d'utilisation
Initialisation
import { TiimeClient } from "tiime-sdk";
// Avec options explicites
const client = new TiimeClient({
companyId: 12345,
email: "vous@example.com",
password: "votre-mot-de-passe",
});
// Ou via env vars (TIIME_EMAIL, TIIME_PASSWORD, TIIME_COMPANY_ID)
const client2 = new TiimeClient();Options
| Option | Type | Description |
|---|---|---|
companyId | number | ID de l'entreprise (optionnel — résolu via TIIME_COMPANY_ID ou config locale) |
email | string | Email du compte (optionnel — résolu via TIIME_EMAIL) |
password | string | Mot de passe (optionnel — résolu via TIIME_PASSWORD) |
tokens | AuthTokens | Tokens d'authentification directe (optionnel — résolu via TIIME_ACCESS_TOKEN) |
tokenManager | TokenManager | Instance custom de TokenManager (optionnel) |
Toutes les options sont optionnelles. Le SDK résout automatiquement l'authentification et le companyId via les variables d'environnement ou les fichiers de configuration locaux.
Lister les entreprises
const companies = await client.listCompanies();
// [{ id: 12345, name: "Mon entreprise", legal_form: "SAS", ... }]Factures
// Lister les factures payées
const invoices = await client.invoices.list({ status: "paid" });
// Toutes les factures (pagination automatique)
const all = await client.invoices.listAll({ status: "sent" });
// Détails d'une facture
const invoice = await client.invoices.get(42);
// Créer une facture
const created = await client.invoices.create({
emission_date: "2026-03-01",
client: { id: 100 },
lines: [
{
description: "Prestation de conseil",
quantity: 5,
unit_amount: 800,
vat_type: { code: "normal" },
invoicing_unit: { id: 3, code: "day" },
},
],
status: "draft",
});
// Modifier une facture
await client.invoices.update(42, { title: "Nouveau titre" });
// Dupliquer une facture
const copy = await client.invoices.duplicate(42, {
emission_date: "2026-04-01",
quantity: 18,
});
// Envoyer par email
await client.invoices.send(42, {
recipients: [{ email: "client@example.com" }],
subject: "Facture mars 2026",
});
// Télécharger le PDF
const pdf = await client.invoices.downloadPdf(42);
// Supprimer un brouillon
await client.invoices.delete(42);Banque
// Soldes de tous les comptes
const balances = await client.bankAccounts.balance();
// Liste des comptes
const accounts = await client.bankAccounts.list(true); // true = actifs uniquement
// Transactions avec filtres et pagination automatique
const transactions = await client.bankTransactions.listAll({
from: "2026-01-01",
to: "2026-01-31",
search: "loyer",
});
// Transactions non imputées
const unimputed = await client.bankTransactions.unimputed();
// Suggestions de label pour une transaction
const suggestions = await client.bankTransactions.labelSuggestions(317543840);
// Imputer une transaction
await client.bankTransactions.impute(317543840, [
{
label: { id: 3901280 },
amount: 25.50,
documents: [],
accountant_detail_requests: [],
},
]);Clients
// Lister les clients actifs
const clients = await client.clients.list({ archived: false });
// Rechercher
const results = await client.clients.search("acme");
// Créer un client
const newClient = await client.clients.create({
name: "ACME Corp",
email: "contact@acme.com",
siren_or_siret: "12345678901234",
city: "Paris",
});
// Détails d'un client
const detail = await client.clients.get(100);Devis
const quotations = await client.quotations.list();
const quotation = await client.quotations.get(10);
const created = await client.quotations.create({
date: "2026-03-01",
client: { id: 100 },
lines: [
{
description: "Mission conseil",
quantity: 10,
unit_amount: 600,
vat_type: { code: "normal" },
invoicing_unit: { id: 3, code: "day" },
},
],
});
await client.quotations.send(10, {
recipients: [{ email: "client@example.com" }],
});
const pdf = await client.quotations.downloadPdf(10);Documents
// Lister les documents
const docs = await client.documents.list({ types: "receipt" });
// Catégories disponibles
const categories = await client.documents.categories();
// Uploader un justificatif
const file = new Uint8Array(/* ... */);
const uploaded = await client.documents.upload(file, "facture.pdf", "receipt");
// Télécharger
const content = await client.documents.download(123);Notes de frais, Labels, Utilisateurs
// Notes de frais
const expenses = await client.expenseReports.list();
const expense = await client.expenseReports.get(5);
await client.expenseReports.create({ name: "Déplacement client" });
// Labels
const labels = await client.labels.list(); // Personnalisés
const standard = await client.labels.standard(); // Plan comptable
const tags = await client.labels.tags(); // Tags
// Utilisateur
const me = await client.users.me();
// Entreprise
const company = await client.company.get();
const period = await client.company.accountingPeriod();Gestion des erreurs
import { TiimeClient, TiimeError } from "tiime-sdk";
try {
const invoice = await client.invoices.get(99999);
} catch (error) {
if (error instanceof TiimeError) {
console.error(`Erreur ${error.status}: ${error.message}`);
console.error(`Endpoint: ${error.endpoint}`);
}
}L'objet TiimeError contient :
| Propriété | Type | Description |
|---|---|---|
message | string | Message d'erreur |
status | number | Code HTTP (404, 422, etc.) |
endpoint | string | URL de l'API appelée |
details | unknown | Détails supplémentaires (optionnel) |
Retry automatique
Le client intègre un mécanisme de retry avec backoff exponentiel sur les erreurs 429 (rate limit) et 5xx (erreurs serveur). Les erreurs 4xx (sauf 429) sont remontées immédiatement.