{
  "name": "Dolibarr AI Agent",
  "nodes": [
    {
      "parameters": {"options": {}},
      "id": "a1b2c3d4-0001-0001-0001-000000000001",
      "name": "Chat Trigger",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [0, 300],
      "webhookId": "dolibarr-chat-trigger-v2"
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "Tu es un assistant expert Dolibarr. Tu aides l'utilisateur a gerer ses tiers, propositions commerciales et factures sur Dolibarr.\n\nComportement obligatoire :\n- Tu poses des questions pour obtenir toutes les informations necessaires avant d'agir\n- Tu resumes TOUJOURS ce que tu vas faire et demandes une confirmation explicite avant d'executer\n- Tu reponds en francais\n- Si une information manque (nom client, description, quantite, prix), tu la demandes\n- Pour creer une facture ou propal, tu as besoin : du client (nom), et au moins une ligne (description, quantite, prix HT)\n- TVA par defaut : 20%\n\nRegles :\n- Ne jamais executer sans confirmation explicite\n- Toujours rechercher le tiers avant de creer une propal ou facture\n- Si le tiers n'existe pas, proposer de le creer d'abord"
        }
      },
      "id": "a1b2c3d4-0002-0002-0002-000000000002",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [300, 300]
    },
    {
      "parameters": {
        "model": "claude-sonnet-4-5",
        "options": {"maxTokensToSample": 4096}
      },
      "id": "a1b2c3d4-0003-0003-0003-000000000003",
      "name": "Claude Sonnet",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.3,
      "position": [150, 520],
      "credentials": {
        "anthropicApi": {"id": "anthropicApi", "name": "Anthropic account"}
      }
    },
    {
      "parameters": {
        "sessionIdType": "fromInput",
        "contextWindowLength": 20
      },
      "id": "a1b2c3d4-0004-0004-0004-000000000004",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [300, 520]
    },
    {
      "parameters": {
        "toolDescription": "Recherche un tiers dans Dolibarr par son nom. Retourne liste avec ID (socid), nom, email. A utiliser avant de creer une propal ou facture.",
        "url": "https://dolibarr.mlsolutions.fr/api/index.php/thirdparties",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {"name": "sqlfilters", "valueProvider": "fieldValue", "value": "={{ \"t.nom:like:'%\" + $fromAI('nom_recherche', 'Nom du tiers a rechercher', 'string') + \"%'\" }}"},
            {"name": "limit", "valueProvider": "fieldValue", "value": "10"}
          ]
        }
      },
      "id": "a1b2c3d4-0005-0005-0005-000000000005",
      "name": "rechercher_tiers",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [0, 520]
    },
    {
      "parameters": {
        "toolDescription": "Cree un nouveau tiers client dans Dolibarr. Champ obligatoire : nom. Optionnels : email, telephone, adresse, code_postal, ville.",
        "method": "POST",
        "url": "https://dolibarr.mlsolutions.fr/api/index.php/thirdparties",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ name: $fromAI('nom', 'Nom du tiers', 'string'), email: $fromAI('email', 'Email optionnel', 'string') || '', phone: $fromAI('telephone', 'Telephone optionnel', 'string') || '', address: $fromAI('adresse', 'Adresse optionnelle', 'string') || '', zip: $fromAI('code_postal', 'Code postal optionnel', 'string') || '', town: $fromAI('ville', 'Ville optionnelle', 'string') || '', country_id: 1, client: 1, fournisseur: 0, status: 1 }) }}"
      },
      "id": "a1b2c3d4-0006-0006-0006-000000000006",
      "name": "creer_tiers",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [150, 700]
    },
    {
      "parameters": {
        "toolDescription": "Cree une proposition commerciale dans Dolibarr. Requis : socid (ID client), lignes [{desc, qty, subprice, tva_tx}]. Optionnel : duree_validite (jours), note_publique, note_privee.",
        "method": "POST",
        "url": "https://dolibarr.mlsolutions.fr/api/index.php/proposals",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ socid: $fromAI('socid', 'ID du client socid', 'number'), date: Math.floor(Date.now()/1000), duree_validite: $fromAI('duree_validite', 'Duree validite en jours defaut 30', 'number') || 30, note_public: $fromAI('note_publique', 'Note publique optionnelle', 'string') || '', note_private: $fromAI('note_privee', 'Note interne optionnelle', 'string') || '', lines: $fromAI('lignes', 'Tableau de lignes : [{desc, qty, subprice, tva_tx}]', 'json') }) }}"
      },
      "id": "a1b2c3d4-0007-0007-0007-000000000007",
      "name": "creer_propal",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [300, 700]
    },
    {
      "parameters": {
        "toolDescription": "Liste les propositions commerciales dans Dolibarr. Retourne ID, reference, client, montant, statut (0=brouillon, 1=validee, 2=signee).",
        "url": "https://dolibarr.mlsolutions.fr/api/index.php/proposals",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {"name": "limit", "valueProvider": "fieldValue", "value": "20"},
            {"name": "sortfield", "valueProvider": "fieldValue", "value": "t.rowid"},
            {"name": "sortorder", "valueProvider": "fieldValue", "value": "DESC"}
          ]
        }
      },
      "id": "a1b2c3d4-0008-0008-0008-000000000008",
      "name": "lister_propals",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [450, 520]
    },
    {
      "parameters": {
        "toolDescription": "Cree une facture dans Dolibarr. Requis : socid (ID client), lignes [{desc, qty, subprice, tva_tx}]. Optionnel : note_publique, note_privee.",
        "method": "POST",
        "url": "https://dolibarr.mlsolutions.fr/api/index.php/invoices",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ socid: $fromAI('socid', 'ID du client socid', 'number'), type: 0, date: Math.floor(Date.now()/1000), note_public: $fromAI('note_publique', 'Note publique optionnelle', 'string') || '', note_private: $fromAI('note_privee', 'Note interne optionnelle', 'string') || '', lines: $fromAI('lignes', 'Tableau de lignes : [{desc, qty, subprice, tva_tx}]', 'json') }) }}"
      },
      "id": "a1b2c3d4-0009-0009-0009-000000000009",
      "name": "creer_facture",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [450, 700]
    },
    {
      "parameters": {
        "toolDescription": "Liste les factures dans Dolibarr. Retourne ID, reference, client, montant TTC, statut (0=brouillon, 1=validee, 2=payee).",
        "url": "https://dolibarr.mlsolutions.fr/api/index.php/invoices",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {"name": "limit", "valueProvider": "fieldValue", "value": "20"},
            {"name": "sortfield", "valueProvider": "fieldValue", "value": "t.rowid"},
            {"name": "sortorder", "valueProvider": "fieldValue", "value": "DESC"}
          ]
        }
      },
      "id": "a1b2c3d4-0010-0010-0010-000000000010",
      "name": "lister_factures",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [600, 520]
    },
    {
      "parameters": {
        "toolDescription": "Valide une facture Dolibarr, la passant de brouillon a emise. Requis : facture_id (ID de la facture).",
        "method": "POST",
        "url": "={{ \"https://dolibarr.mlsolutions.fr/api/index.php/invoices/\" + $fromAI('facture_id', 'ID de la facture a valider', 'number') + \"/validate\" }}",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{}"
      },
      "id": "a1b2c3d4-0011-0011-0011-000000000011",
      "name": "valider_facture",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [600, 700]
    },
    {
      "parameters": {
        "toolDescription": "Obtient le PDF d'une propal ou facture Dolibarr. modulepart = 'propal' ou 'invoice'. document_id = ID du document.",
        "url": "https://dolibarr.mlsolutions.fr/api/index.php/documents/download",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {"name": "DOLAPIKEY", "valueProvider": "fieldValue", "value": "0b0e03741e10306bcb7f3f76923a6060b752b03d"},
            {"name": "Content-Type", "valueProvider": "fieldValue", "value": "application/json"}
          ]
        },
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {"name": "modulepart", "valueProvider": "fieldValue", "value": "={{ $fromAI('modulepart', 'propal ou invoice', 'string') }}"},
            {"name": "id", "valueProvider": "fieldValue", "value": "={{ $fromAI('document_id', 'ID du document', 'number') }}"}
          ]
        }
      },
      "id": "a1b2c3d4-0012-0012-0012-000000000012",
      "name": "telecharger_pdf",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [750, 520]
    }
  ],
  "connections": {
    "Chat Trigger": {"main": [[{"node": "AI Agent", "type": "main", "index": 0}]]},
    "Claude Sonnet": {"ai_languageModel": [[{"node": "AI Agent", "type": "ai_languageModel", "index": 0}]]},
    "Window Buffer Memory": {"ai_memory": [[{"node": "AI Agent", "type": "ai_memory", "index": 0}]]},
    "rechercher_tiers": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]},
    "creer_tiers": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]},
    "creer_propal": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]},
    "lister_propals": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]},
    "creer_facture": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]},
    "lister_factures": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]},
    "valider_facture": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]},
    "telecharger_pdf": {"ai_tool": [[{"node": "AI Agent", "type": "ai_tool", "index": 0}]]}
  },
  "pinData": {},
  "settings": {"executionOrder": "v1"},
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2026-04-22T00:00:00.000Z",
  "versionId": "dolibarr-agent-v2"
}
