Upload dropbox doesn't work

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)


## Share the output returned by the last node
<!-- If you need help with data transformations, please also share your expected output. -->

## Information on your n8n setup
- **n8n version:**
- **Database (default: SQLite):**
- **n8n EXECUTIONS_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**
- **Operating system:**Preformatted text

{
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $binary.data.fileExtension }}",
              "value2": "pdf"
            }
          ]
        }
      },
      "id": "15e61791-fd57-49a7-b5d1-565451a13323",
      "name": "Is PDF",
      "type": "n8n-nodes-base.if",
      "position": [
        2100,
        200
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "d256b71f-46a1-453d-bf66-db87ae8f6eb4",
      "name": "Not a PDF",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2420,
        400
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "// https://community.n8n.io/t/iterating-over-email-attachments/13588/3\nlet results = [];\n\nfor (const item of $input.all()) {\n  for (key of Object.keys(item.binary)) {\n        results.push({\n            json: {},\n            binary: {\n                data: item.binary[key],\n            }\n        });\n    }\n}\n\nreturn results;"
      },
      "id": "f2e49058-d4b1-4288-94a1-3418e118ffe1",
      "name": "Iterate over email attachments",
      "type": "n8n-nodes-base.code",
      "position": [
        1780,
        100
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {},
        "options": {
          "dataPropertyAttachmentsPrefixName": "attachment_",
          "downloadAttachments": true
        }
      },
      "id": "93a7c381-4eec-4d10-9ecf-96dfdcaa3d53",
      "name": "On email received",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        520,
        220
      ],
      "typeVersion": 1,
      "credentials": {
        "gmailOAuth2": {
          "id": "lPW7SfWSh9xBPkVW",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "content": "### Configuration\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n__`Match on`(required)__: What should OpenAI's search term be? Examples: invoice, callsheet, receipt, contract, payslip.\n__`Google Drive folder to upload matched PDFs`(required)__: Paste the link of the GDrive folder, an example has been provided but will need to change to a folder you own.\n__`maxTokenSize`(required)__: The maximum token size for the model you choose. See possible models from OpenAI [here](https://platform.openai.com/docs/models/gpt-3).\n__`replyTokenSize`(required)__: The reply's maximum token size. Default is 300. This determines how much text the AI will reply with.",
        "height": 607.9684549079709,
        "width": 259.0890718059702
      },
      "id": "ac1325f4-e372-4303-ad8f-c2969924ccbf",
      "name": "Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        140
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $('On email received').item.binary.isNotEmpty() }}",
              "value2": true
            }
          ]
        }
      },
      "id": "19718b1e-ddee-4356-b381-e4c1f9c2be06",
      "name": "Has attachments?",
      "type": "n8n-nodes-base.if",
      "position": [
        1500,
        100
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "8fb18399-8766-400f-a0e7-a34f9b1dbb09",
      "name": "There are no attachments",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1820,
        400
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "maxTokenSize",
              "value": 200000
            },
            {
              "name": "replyTokenSize",
              "value": 50
            }
          ],
          "string": [
            {
              "name": "Match on",
              "value": "expertise, expertises, maître, expert, experts, convocation"
            },
            {
              "name": "Dropbox  folder",
              "value": "/Expertises/a classer"
            }
          ]
        },
        "options": {
          "dotNotation": false
        }
      },
      "id": "6564abd3-e50a-4fd5-b713-f7c52f6faa45",
      "name": "Configure",
      "type": "n8n-nodes-base.set",
      "position": [
        740,
        220
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "// Code avec gestion plus robuste de la structure de l'expéditeur\nconst email = items[0];\nconst keywords = $node[\"Configure\"].json[\"Match on\"].split(',').map(k => k.trim().toLowerCase());\n\n// Préparation des champs à vérifier\nconst subject = typeof email.json.subject === 'string' ? email.json.subject.toLowerCase() : '';\nconst body = typeof email.json.text === 'string' ? email.json.text.toLowerCase() : \n             (typeof email.json.html === 'string' ? email.json.html.toLowerCase() : '');\n\n// Affichage des données pour comprendre la structure\nconsole.log(\"Structure de email.json.from:\", JSON.stringify(email.json.from, null, 2));\n\n// Extraction de l'expéditeur de manière plus robuste\nlet sender = '';\nif (email.json.from) {\n  if (typeof email.json.from === 'string') {\n    sender = email.json.from.toLowerCase();\n  } else {\n    // Récupération de toutes les valeurs possibles dans l'objet from\n    const fromStr = JSON.stringify(email.json.from).toLowerCase();\n    sender = fromStr;\n  }\n}\n\nconsole.log(\"Mots-clés recherchés:\", keywords);\nconsole.log(\"Sujet:\", subject);\nconsole.log(\"Corps:\", body);\nconsole.log(\"Expéditeur (traité):\", sender);\n\n// Recherche des mots-clés\nconst matchedKeywords = [];\nkeywords.forEach(keyword => {\n  if (subject.includes(keyword) || body.includes(keyword) || sender.includes(keyword)) {\n    matchedKeywords.push(keyword);\n  }\n});\n\nconsole.log(\"Mots-clés trouvés:\", matchedKeywords);\n\n// Résultat avec le statut de correspondance\nreturn [{\n  json: {\n    matched: matchedKeywords.length > 0,\n    matchedKeywords: matchedKeywords,\n    ...email.json\n  },\n  binary: email.binary\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1000,
        220
      ],
      "id": "c2c91e44-1054-4bfc-abf2-a1ac9a5f232d",
      "name": "Code"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "59996579-78b5-435c-bde7-d20b92ff6e67",
              "leftValue": "={{ $json.matched }}",
              "rightValue": "true",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1240,
        220
      ],
      "id": "a09a5321-ea23-4832-8ce0-d6371278264a",
      "name": "If"
    },
    {
      "parameters": {
        "jsCode": "// Ne générez plus le chemin ici, laissez Dropbox le gérer\nreturn $input.item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2460,
        -160
      ],
      "id": "167e8767-1b2e-4b9d-b7b6-c02f90dbedd5",
      "name": "Code1"
    },
    {
      "parameters": {
        "path": "/Expertises/a classer",
        "binaryData": true
      },
      "type": "n8n-nodes-base.dropbox",
      "typeVersion": 1,
      "position": [
        2900,
        -140
      ],
      "id": "403888a4-f002-4403-a18c-472d60c78578",
      "name": "Dropbox",
      "alwaysOutputData": false,
      "notesInFlow": false,
      "credentials": {
        "dropboxApi": {
          "id": "eXgrkUGqm7MEnGkw",
          "name": "Dropbox account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return {\n  json: {\n    debug_output: $input.all()[0].json,\n    error_details: $node[\"Dropbox\"].error\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3200,
        -140
      ],
      "id": "a0a2b704-857d-47e0-b93a-013766703a1b",
      "name": "Code2"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.item;\nconst cleanName = item.binary.data.fileName\n  .normalize('NFD').replace(/[\\u0300-\\u036f]/g, '') // Supprime les accents\n  .replace(/[^a-zA-Z0-9\\-._]/g, '') // Garde seulement les caractères autorisés\n  .replace(/\\s+/g, '_') // Remplace les espaces\n  .replace(/_+/g, '_') // Évite les doubles underscores\n  .substring(0, 60); // Limite la longueur\n\nitem.binary.data.fileName = cleanName + '.pdf'; // Force l'extension .pdf\nreturn item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2620,
        -360
      ],
      "id": "465d3aee-9c27-4bb2-bfd9-b5b1fbe44ee7",
      "name": "Code3"
    }
  ],
  "connections": {
    "Is PDF": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Not a PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Iterate over email attachments": {
      "main": [
        [
          {
            "node": "Is PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On email received": {
      "main": [
        [
          {
            "node": "Configure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has attachments?": {
      "main": [
        [
          {
            "node": "Iterate over email attachments",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "There are no attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Has attachments?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "Code3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dropbox": {
      "main": [
        [
          {
            "node": "Code2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code3": {
      "main": [
        [
          {
            "node": "Dropbox",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "5aca7def009eaa74e78320ff0934731ae61df85207848e1910db1e4a571ea3ba"
  }
}