TAR Calculator API

v2.0.0 - Calcul automatique des taxes de recyclage

Tester en live

2 endpoints disponibles selon votre use case

• /api/calculate-tar-v2 - Pour recherche libre avec IA
Utilise Claude AI pour identifier le produit depuis une description. Idéal pour recherche manuelle ou données non structurées.
• /api/calculate-tar-odeal - Pour formulaire Odeal
Exploite les subcategories et données structurées du formulaire. Calcul instantané sans IA (rapide, précis, déterministe).
URL de base
Développement
http://localhost:3004
Production
https://tar.odl-tools.ch
POST/api/calculate-tar-v2

Calcul intelligent de la TAR avec extraction automatique des spécifications (poids, dimensions, taille écran). Utilise Claude AI et inclut un cache Supabase pour des performances optimales.

Body (JSON)

{
  "ean": "5099206071131",                      // EAN (optionnel)
  "description": "Clavier sans fil Logitech K270", // OBLIGATOIRE (min 10 car.)
  "type_produit": "clavier",                   // OBLIGATOIRE (min 3 car.)
  "marque": "Logitech",                        // Optionnel
  "poids": 0.5                                 // Poids en kg (optionnel)
}

Réponse

{
  "success": true,
  "source": "enriched_extraction",  // ou "cache_enriched"
  "confidence": 95,
  "product": {
    "nom_produit": "Clavier sans fil Logitech K270",
    "marque": "Logitech",
    "poids_kg": 0.5,
    "image_url": "https://...",
    "description": "Clavier compact...",
    "dimensions": {
      "length_cm": 45.0,
      "width_cm": 15.5,
      "height_cm": 2.5
    }
  },
  "tar": {
    "organisme": "SWICO",
    "categorie": "peripherique",
    "type": "Périphérique informatique",
    "tarifHT": "0.46",
    "tarifTTC": "0.50",
    "tva": 8.1,
    "alternatives": null,
    "notes": []
  },
  "enriched_data": { /* Données enrichies complètes */ }
}
Champs obligatoires pour V2
  • type_produit : minimum 3 caractères (ex: "clavier", "écran", "tablette")
  • description : minimum 10 caractères
  • • Les autres champs sont optionnels mais améliorent la précision

Exemple cURL

curl -X POST https://tar.odl-tools.ch/api/calculate-tar-v2 \
  -H "Content-Type: application/json" \
  -d '{
    "ean": "5099206071131",
    "description": "Clavier sans fil Logitech K270",
    "type_produit": "clavier",
    "marque": "Logitech",
    "poids": 0.5
  }'
POST/api/calculate-tar-odealFORMULAIRE ODEAL

Endpoint optimisé pour le formulaire Odeal. Exploite les subcategories et données structurées pour un calcul TAR instantané et déterministe (sans IA). Performance : <50ms de réponse.

Body (JSON)

{
  "item_name": "iPhone 15 Pro",           // OBLIGATOIRE - Nom du produit
  "subcategory_id": "s20",                 // OBLIGATOIRE - ID subcategory (s1-s65)
  "has_battery": true,                     // Optionnel - Produit contient batterie
  "battery_type": "lithium_ion_rechargeable", // Si has_battery = true
  "ean": "194252721444",                   // Optionnel
  "sku": "SKU-123",                        // Optionnel
  "weight_kg": 0.221,                      // Optionnel (requis pour SENS)
  "length_cm": 15.5,                       // Optionnel
  "width_cm": 7.5,                         // Optionnel
  "height_cm": 0.8                         // Optionnel
}

Réponse

{
  "success": true,
  "source": "odeal_form",
  "confidence": 95,
  "product": {
    "nom_produit": "iPhone 15 Pro",
    "subcategory_id": "s20",
    "ean": "194252721444",
    "sku": "SKU-123",
    "poids_kg": 0.221,
    "dimensions": {
      "length_cm": 15.5,
      "width_cm": 7.5,
      "height_cm": 0.8
    },
    "battery": {
      "has_battery": true,
      "type": "lithium_ion_rechargeable"
    }
  },
  "tar": {
    "organisme": "SWICO",
    "categorie": "smartphone",
    "type": "Smartphone/Smartwatch",
    "tarifHT": "0.19",
    "tarifTTC": "0.21",
    "tva": 8.1,
    "calculation_method": "subcategory_mapping",
    "notes": [
      "Catégorie identifiée depuis subcategory s20",
      "Tarif SWICO standard appliqué: CHF 0.19"
    ]
  },
  "validation": {
    "warnings": []
  }
}
Subcategories supportées

s20 : Téléphonie (SWICO) - CHF 0.19

s21 : Informatique (SWICO) - Variable selon taille écran

s24-s25 : Électroménager (SENS) - Variable selon poids

s1-s19 : Mode, Maison (AUCUN TAR)

📋 65 subcategories mappées → Voir fichier subcategory-tar-mapping.js

Types de batteries supportés
  • alkaline_non_rechargeable - Pile alcaline
  • lithium_ion_rechargeable - Batterie Li-ion
  • lithium_metal_non_rechargeable - Pile lithium métal
  • lead_acid - Batterie au plomb
  • nickel_metal_hydride - Batterie NiMH
  • other - Autre type

Exemples cURL

Exemple 1 : Smartphone

curl -X POST https://tar.odl-tools.ch/api/calculate-tar-odeal \
  -H "Content-Type: application/json" \
  -d '{
    "item_name": "iPhone 15 Pro",
    "subcategory_id": "s20",
    "has_battery": true,
    "weight_kg": 0.187
  }'

Exemple 2 : Ordinateur portable

curl -X POST https://tar.odl-tools.ch/api/calculate-tar-odeal \
  -H "Content-Type: application/json" \
  -d '{
    "item_name": "MacBook Pro 16",
    "subcategory_id": "s21",
    "weight_kg": 2.1,
    "length_cm": 35.57,
    "width_cm": 24.81
  }'

Exemple 3 : Électroménager

curl -X POST https://tar.odl-tools.ch/api/calculate-tar-odeal \
  -H "Content-Type: application/json" \
  -d '{
    "item_name": "Lave-linge Bosch",
    "subcategory_id": "s24",
    "weight_kg": 68
  }'

Exemples d'intégration Odeal

Weweb (REST API)
// Configuration du REST API Data Source dans Weweb
Base URL: https://tar.odl-tools.ch
Endpoint: /api/calculate-tar-odeal
Method: POST
Headers:
  Content-Type: application/json

// Body (bindings depuis formulaire Odeal)
{
  "item_name": {{form_item_name}},
  "subcategory_id": {{form_subcategory}},
  "has_battery": {{form_has_battery}},
  "battery_type": {{form_battery_type}},
  "weight_kg": {{form_weight}},
  "length_cm": {{form_length}},
  "width_cm": {{form_width}}
}

// Afficher le résultat
{{api_response.data.tar.tarifTTC}} CHF TTC
{{api_response.data.tar.organisme}} ({{api_response.data.tar.type}})
N8N (HTTP Request Node)
// Node: HTTP Request
Method: POST
URL: https://tar.odl-tools.ch/api/calculate-tar-odeal

// Body (JSON)
{
  "item_name": "{{$json.item_name}}",
  "subcategory_id": "{{$json.subcategory_id}}",
  "has_battery": {{$json.has_battery}},
  "weight_kg": {{$json.weight_kg}},
  "length_cm": {{$json.length_cm}},
  "width_cm": {{$json.width_cm}}
}

// Extraire les résultats dans le workflow suivant
{{ $json.tar.tarifTTC }}     // Tarif TTC
{{ $json.tar.tarifHT }}      // Tarif HT
{{ $json.tar.organisme }}    // SWICO/SENS/INOBAT
{{ $json.tar.type }}         // Type de produit
{{ $json.confidence }}       // Score de confiance (95% si toutes données OK)

Exemples d'intégration V2 (avec IA)

Weweb (REST API)

// Configuration du REST API Data Source dans Weweb
Base URL: http://localhost:3004 (ou https://tar.odl-tools.ch en prod)
Endpoint: /api/calculate-tar-v2
Method: POST
Headers:
  Content-Type: application/json

// Body (bindings Weweb)
{
  "ean": {{input_ean.value}},
  "description": {{input_description.value}},
  "type_produit": {{input_type.value}},
  "marque": {{input_marque.value}},
  "poids": {{input_poids.value}}
}

// Afficher le résultat
{{api_response.data.tar.tarifTTC}} CHF TTC

N8N (HTTP Request Node)

// Node: HTTP Request
Method: POST
URL: http://localhost:3004/api/calculate-tar-v2

// Body (JSON)
{
  "ean": "{{$json.ean}}",
  "description": "{{$json.description}}",
  "type_produit": "{{$json.type}}",
  "marque": "{{$json.marque}}"
}

// Extraire les résultats dans le workflow suivant
{{ $json.tar.tarifTTC }}  // Tarif TTC
{{ $json.tar.organisme }} // Organisme TAR
{{ $json.confidence }}     // Score de confiance

Supabase Edge Function

// supabase/functions/calculate-tar/index.ts
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"

serve(async (req) => {
  const { ean, description, type_produit } = await req.json()

  const response = await fetch('http://localhost:3004/api/calculate-tar-v2', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ ean, description, type_produit })
  })

  const data = await response.json()

  // Sauvegarder dans Supabase
  const { error } = await supabaseClient
    .from('tar_calculations')
    .insert({
      ean,
      product_name: data.product.nom_produit,
      tar_ht: data.tar.tarifHT,
      tar_ttc: data.tar.tarifTTC,
      organism: data.tar.organisme
    })

  return new Response(JSON.stringify(data), {
    headers: { 'Content-Type': 'application/json' }
  })
})

Health Check

GET/health

Vérifier l'état du serveur et les versions des barèmes

curl http://localhost:3004/health