AutomationFlowsAI & RAG › Automate PDF Purchase Orders to Sales Orders in Adobe Commerce with AI

Automate PDF Purchase Orders to Sales Orders in Adobe Commerce with AI

ByJKingma @jkingma on n8n.io

This n8n template demonstrates how to automatically process PDF purchase orders received via email and convert them into sales orders in Adobe Commerce (Magento 2) using Company Credit as the payment method.

Event trigger★★★★★ complexityAI-powered96 nodesHTTP RequestForm TriggerChat TriggerStop And ErrorMicrosoft Outlook TriggerAgentMicrosoft OutlookLm Chat Azure Open Ai
AI & RAG Trigger: Event Nodes: 96 Complexity: ★★★★★ AI nodes: yes Added:

This workflow corresponds to n8n.io template #8388 — we link there as the canonical source.

This workflow follows the Agent → Chat Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "qfERlqqAvDjUMxQZ",
  "name": "PDF-to-order",
  "tags": [],
  "nodes": [
    {
      "id": "9890e277-89bd-4a3a-995f-eb06252cd1f6",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "disabled": true,
      "position": [
        128,
        1264
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "395233c3-597c-4704-aa34-95700166f2ee",
      "name": "Create cart",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        6288,
        672
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/customers/{{ $('set Customer').item.json.customer.id}}/carts",
        "method": "POST",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f2c25774-8c2e-4d83-9029-1ddcec3f1be9",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "disabled": true,
      "position": [
        -96,
        1264
      ],
      "parameters": {
        "options": {},
        "formTitle": "PDF",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "data",
              "multipleFiles": false,
              "requiredField": true,
              "acceptFileTypes": ".pdf"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "dc25383f-c225-4b9b-a0a3-187281aeb673",
      "name": "set Customer",
      "type": "n8n-nodes-base.set",
      "position": [
        5552,
        784
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b86f06ee-7dd4-46ec-a865-cd8312721771",
              "name": "customer",
              "type": "object",
              "value": "={{ $json.items[0] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0f4c3f39-7dd7-4f30-a08d-e71d6a7b6522",
      "name": "set Quote Id",
      "type": "n8n-nodes-base.set",
      "position": [
        6560,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "861cd718-14ef-485f-8b32-94702984d310",
              "name": "quote_id",
              "type": "string",
              "value": "={{ $json }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "02230beb-0a2b-4e95-84cb-fbf1fd66ba0c",
      "name": "set Billing Address",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        11696,
        656
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/billing-address",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"address\": {\n    \"customer_address_id\": {{ $('set Address').first().json.id }}\n  },\n  \"useForShipping\": true\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "6a0265b7-1ced-4d10-a8b6-b904a696097f",
      "name": "estimate Shipping Methods",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        11920,
        656
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/estimate-shipping-methods",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"address\": {\n    \"firstname\": \"{{ $('set Customer').first().json.customer.addresses[0].firstname }}\",\n    \"lastname\": \"{{ $('set Customer').first().json.customer.addresses[0].lastname }}\",\n    \"street\": {{ JSON.stringify($('set Customer').first().json.customer.addresses[0].street) }},\n    \"city\": \"{{ $('set Customer').first().json.customer.addresses[0].city }}\",\n    \"postcode\": \"{{ $('set Customer').first().json.customer.addresses[0].postcode }}\",\n    \"region\": \"{{ $('set Customer').first().json.customer.addresses[0].region.region }}\",\n    \"country_id\": \"{{ $('set Customer').first().json.customer.addresses[0].country_id }}\"\n  }\n}\n",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "1fe3857b-dc7a-4147-b318-c02f703300d5",
      "name": "set Reference Number",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        13088,
        656
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/set-reference-number",
        "method": "PUT",
        "options": {},
        "jsonBody": "={\n    \"number\": \"{{ $('set OpenAI').first().json.content.po_number }}\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "2908f698-e451-4d37-a3f5-02d7cd88e505",
      "name": "set OpenAI",
      "type": "n8n-nodes-base.set",
      "position": [
        2016,
        1168
      ],
      "parameters": {
        "options": {
          "ignoreConversionErrors": true
        },
        "assignments": {
          "assignments": [
            {
              "id": "4501fdd9-135b-4717-92bd-fd591492e0ea",
              "name": "content",
              "type": "object",
              "value": "={{ JSON.parse($json.output) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "491bd788-b44e-41b9-9c1c-fd58d71bccc8",
      "name": "set Order Comment",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        13312,
        656
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/order-comment",
        "method": "PUT",
        "options": {},
        "jsonBody": "={\n    \"comment\": \"The order has been automatically processed\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "6a9d7577-4008-42ff-a1ab-02a5e8f994d1",
      "name": "get Payment Methods",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        13536,
        656
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/payment-methods",
        "options": {},
        "jsonBody": "={\n  \"address\": {\n    \"firstname\": \"{{ $('set Customer').first().json.customer.addresses[0].firstname }}\",\n    \"lastname\": \"{{ $('set Customer').first().json.customer.addresses[0].lastname }}\",\n    \"street\": {{ JSON.stringify($('set Customer').first().json.customer.addresses[0].street) }},\n    \"city\": \"{{ $('set Customer').first().json.customer.addresses[0].city }}\",\n    \"postcode\": \"{{ $('set Customer').first().json.customer.addresses[0].postcode }}\",\n    \"region\": \"{{ $('set Customer').first().json.customer.addresses[0].region.region }}\",\n    \"country_id\": \"{{ $('set Customer').first().json.customer.addresses[0].country_id }}\"\n  }\n}\n",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "6ff7ff4f-dbeb-45f6-8307-25a8e931c1d8",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        11344,
        528
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "1249cf58-e268-4039-b3e2-44fdf66b7a82",
      "name": "check Companycredit",
      "type": "n8n-nodes-base.code",
      "position": [
        13744,
        656
      ],
      "parameters": {
        "jsCode": "const items = $input.all(); // get all items\nconst paymentMethods = items.map(i => i.json); // extract JSON from each\n\nconst hasCompanyCredit = paymentMethods.some(method => method.code === 'companycredit');\n\nreturn [{\n  json: {\n    hasCompanyCredit\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "e8a9fdec-1d08-41ef-b926-321da7390669",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "disabled": true,
      "position": [
        -96,
        1056
      ],
      "parameters": {
        "options": {
          "allowFileUploads": true,
          "allowedFilesMimeTypes": "pdf"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "79ce029f-ec9c-45ad-b55d-4dbe8c8ec5cd",
      "name": "Extract from File1",
      "type": "n8n-nodes-base.extractFromFile",
      "disabled": true,
      "position": [
        128,
        1056
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "data0"
      },
      "typeVersion": 1
    },
    {
      "id": "d2120bca-773d-4c2e-a404-1e1aad88a198",
      "name": "set Address",
      "type": "n8n-nodes-base.code",
      "position": [
        5712,
        784
      ],
      "parameters": {
        "jsCode": "const addresses = $json.customer.addresses || [];\n\nconst defaultAddress = addresses.find(addr => addr.default_shipping === true);\n\nreturn [{\n  json: {\n    ...defaultAddress\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "05efafa7-bbd0-409b-b1c7-e38030a87030",
      "name": "get Configurable",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        7680,
        816
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku_search&searchCriteria[filter_groups][0][filters][0][value]={{ $json.clean_articlenumber }}&searchCriteria[filter_groups][0][filters][0][condition_type]=eq",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "72eca58d-c3e0-47c9-82d7-3dff8207fbde",
      "name": "If companyCredit",
      "type": "n8n-nodes-base.if",
      "position": [
        13968,
        656
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e2a48e26-f9ee-4b4b-84c5-f4b1759a4474",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.hasCompanyCredit }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "180a1faf-014b-41ec-a1e8-e6cf36ca9263",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        7904,
        688
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.1
    },
    {
      "id": "736d887a-006d-4aa3-b4ba-4344ba00aea8",
      "name": "set Express Shipping Method",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        12576,
        752
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/shipping-information",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"addressInformation\": {\n    \"shipping_address\": {\n       \"customer_address_id\": {{ $('set Customer').first().json.customer.addresses[0].id }},\n       \"country_id\": \"{{ $('set Customer').first().json.customer.addresses[0].country_id }}\"\n    },\n    \"shipping_carrier_code\": \"{{ $input.last().json.carrier_code }}\",\n    \"shipping_method_code\": \"{{ $input.last().json.method_code}}\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "12b39d6f-1265-4134-8c33-53b8629a01b7",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        12144,
        656
      ],
      "parameters": {
        "maxItems": 2
      },
      "typeVersion": 1
    },
    {
      "id": "44611b16-16a4-4a21-a73d-15a9d022239b",
      "name": "set Standard Shipping Method",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        12576,
        544
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/shipping-information",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"addressInformation\": {\n    \"shipping_address\": {\n       \"customer_address_id\": {{ $('set Customer').first().json.customer.addresses[0].id }},\n       \"country_id\": \"{{ $('set Customer').first().json.customer.addresses[0].country_id }}\"\n    },\n    \"shipping_carrier_code\": \"{{ $input.first().json.carrier_code }}\",\n    \"shipping_method_code\": \"{{ $input.first().json.method_code}}\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "384255bb-4301-4a4d-a08e-b25cf8f8c13c",
      "name": "set Feedback",
      "type": "n8n-nodes-base.set",
      "position": [
        6144,
        1936
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7d430e2c-bc0f-4f7a-a718-e0f4a0e21a51",
              "name": "message",
              "type": "string",
              "value": "=No customers found in the webshop with emailadresses: {{ $('filter Emailadresses').item.json.content.email }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "fa659e1c-24ec-4540-b973-115a998a8bb4",
      "name": "set Clean Articlenumber",
      "type": "n8n-nodes-base.set",
      "position": [
        7440,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1f4f162f-225c-41ae-b985-ae8962e6cccf",
              "name": "clean_articlenumber",
              "type": "string",
              "value": "={{ $json.articlenumber.replace(/[^a-zA-Z0-9]/g, '') }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "6a43fd7f-c7fb-4365-815f-315028af24b0",
      "name": "get Cart Items",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        6912,
        480
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $json.quote_id }}/items",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "81a33420-77c6-4986-a1b4-84d222b7fc7f",
      "name": "remove From Shopping Cart",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        7136,
        480
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $json.quote_id }}/items/{{ $json.item_id }}",
        "method": "DELETE",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "28409228-4cc4-47f0-be65-b4f1a94d7b8e",
      "name": "get Cart Items1",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        14416,
        112
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ parseFloat($('set Quote Id').item.json.quote_id) }}/items",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2f6e189d-c322-43a1-83a9-3a3ca8f34567",
      "name": "remove From Shopping Cart1",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        14640,
        112
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $json.quote_id }}/items/{{ $json.item_id }}",
        "method": "DELETE",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f378aa93-9039-4003-aba8-466f9f32abfd",
      "name": "If Default Address",
      "type": "n8n-nodes-base.if",
      "position": [
        5872,
        784
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fd484e2d-1124-4e78-a62a-efb39095b107",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "92de4eba-62fd-4314-a15d-ebcd4d0440b0",
      "name": "set Feedback Default Address",
      "type": "n8n-nodes-base.set",
      "position": [
        6144,
        1744
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7d430e2c-bc0f-4f7a-a718-e0f4a0e21a51",
              "name": "message",
              "type": "string",
              "value": "=No default address found for customer {{ $('set Customer').item.json.customer.email }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "210ebce0-2feb-4bac-9b69-92f2848db0ed",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        2944,
        944
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Company1",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "40cc7660-de4b-49cc-8ff2-cbca3e3d77b6",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $json.content.address.company_name }}",
                    "rightValue": "Company 1"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Customer",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "91a71674-3d80-4b59-a1de-020fde68bbbd",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ JSON.stringify($json.content.email) }}",
                    "rightValue": "@customer.com"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "7cb9f161-8a1e-4888-bdac-7249612472e5",
      "name": "Extract from File2",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        832
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "attachment"
      },
      "typeVersion": 1
    },
    {
      "id": "528b43cb-d102-4773-9801-200e4e96cba5",
      "name": "Stop and Error1",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        15264,
        2048
      ],
      "parameters": {
        "errorMessage": "={{ $json.message }}"
      },
      "typeVersion": 1
    },
    {
      "id": "1ca9c9d2-5e09-445c-b1da-d67e9f56af7b",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1248,
        1168
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "bcfa313b-0206-4212-be8b-e58d11dfc077",
      "name": "Json error message",
      "type": "n8n-nodes-base.set",
      "position": [
        15040,
        2048
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "6bd733dc-147d-401f-9399-4d8cdf85190a",
              "name": "message",
              "type": "string",
              "value": "={{ JSON.stringify($json) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "150f9f98-f67b-47ab-9f88-83ea2e55fc1b",
      "name": "Combine error fields",
      "type": "n8n-nodes-base.set",
      "position": [
        14816,
        2048
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "dc806cb3-a93c-4520-86d1-7e7e948b269d",
              "name": "message",
              "type": "string",
              "value": "={{ $json.message }}"
            },
            {
              "id": "f8f9d4dd-6de8-4d3d-9c38-971f870dd8be",
              "name": "email_id",
              "type": "string",
              "value": "={{ $('Email combine').first().json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "fc4c479f-7e30-4e25-ad5c-1ede51dc7c33",
      "name": "No Operation, do nothing1",
      "type": "n8n-nodes-base.noOp",
      "position": [
        12032,
        1952
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "aa105f7b-cc4a-4430-afdd-a3e3a26365de",
      "name": "Set successfull message",
      "type": "n8n-nodes-base.set",
      "disabled": true,
      "position": [
        14864,
        112
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0385f122-a92b-4061-b5fb-10d27ad59dff",
              "name": "message",
              "type": "string",
              "value": "Everything good, cart cleared"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "838353b2-48bf-4eef-80bd-4ea7a2bb2522",
      "name": "Set empty email message",
      "type": "n8n-nodes-base.set",
      "position": [
        3024,
        2144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "50596fcc-fd14-4554-88a7-919c9826b68b",
              "name": "message",
              "type": "string",
              "value": "No emailaddresses found in PDF"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a4e45594-4286-4f68-8f21-6c00100e8336",
      "name": "Set empty products message",
      "type": "n8n-nodes-base.set",
      "position": [
        3024,
        1936
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "50596fcc-fd14-4554-88a7-919c9826b68b",
              "name": "message",
              "type": "string",
              "value": "No products found in PDF"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "136e83aa-750d-4c0d-938a-e470de35e5e6",
      "name": "Products not empty",
      "type": "n8n-nodes-base.if",
      "position": [
        2688,
        1072
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "890a4093-c76d-4667-99f2-d045ce4ee440",
              "operator": {
                "type": "array",
                "operation": "lengthGte",
                "rightType": "number"
              },
              "leftValue": "={{ $json.content.products }}",
              "rightValue": 1
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b65ce8b3-f91f-4c1f-9bcd-7fcc6158ece0",
      "name": "Emails not empty",
      "type": "n8n-nodes-base.if",
      "position": [
        2464,
        1168
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "176ded4d-8dce-4149-9303-67a39a7c10b5",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.content.email.length }}",
              "rightValue": 1
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "354d7cd2-3cc4-40b8-8e9c-95e9579715a4",
      "name": "set Information",
      "type": "n8n-nodes-base.set",
      "position": [
        1024,
        832
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8cf26a57-2a4f-4b12-bb62-032be07ff461",
              "name": "info",
              "type": "string",
              "value": "={{ $('Email combine').first().json.text }}\n{{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "76a4df77-73b6-4ee1-be21-7429a5a743bb",
      "name": "set Information 2",
      "type": "n8n-nodes-base.set",
      "disabled": true,
      "position": [
        352,
        1168
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8b70af92-d07d-4002-8d8d-b22f6d06d55c",
              "name": "info",
              "type": "string",
              "value": "=jellekingm@gmail.com\n{{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "df152c99-cb59-41ae-ac76-0429d1531767",
      "name": "Pay on account error message",
      "type": "n8n-nodes-base.set",
      "position": [
        14480,
        1680
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "50596fcc-fd14-4554-88a7-919c9826b68b",
              "name": "message",
              "type": "string",
              "value": "No pay on account for this client"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8888ccf9-b3ea-44e9-a50a-c6cb827ff423",
      "name": "Set empty PO number message",
      "type": "n8n-nodes-base.set",
      "position": [
        4224,
        1808
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "50596fcc-fd14-4554-88a7-919c9826b68b",
              "name": "message",
              "type": "string",
              "value": "No PO number found in PDF"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7a0daa68-cf6c-4fce-b0b2-fdc4c6aa92a0",
      "name": "If PO number not empty",
      "type": "n8n-nodes-base.if",
      "position": [
        3744,
        992
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a9233974-706e-4cfb-b382-737d35c02ed5",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.content.po_number }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "521ca2ab-920f-4092-86e6-69fa938c2469",
      "name": "Vorgangsnummer",
      "type": "n8n-nodes-base.set",
      "position": [
        3184,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "2cca615c-aae6-43b5-ab3e-f98e4dabd68a",
              "name": "content.po_number",
              "type": "string",
              "value": "={{ $json.content.extra_fields.Vorgangsnummer }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "338aa109-d64a-4667-92b9-206c973fb68e",
      "name": "No Operation, do nothing3",
      "type": "n8n-nodes-base.noOp",
      "position": [
        5792,
        2160
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "1df3130a-94c7-40ea-a214-78a46a420a68",
      "name": "Split Out Products",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        7200,
        672
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "=products"
      },
      "typeVersion": 1
    },
    {
      "id": "5b4e4cd7-e891-4466-b9f1-396b7cfb4c8c",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        592,
        832
      ],
      "parameters": {
        "jsCode": "const results = [];\n\nfor (const item of items) {\n  for (const key in item.binary) {\n    if (\n      Object.prototype.hasOwnProperty.call(item.binary, key) &&\n      (item.binary[key].mimeType === 'application/pdf' || (item.binary[key].mimeType === 'application/octet-stream' && item.binary[key].fileExtension === 'pdf') )\n    ) {\n      results.push({\n        json: {\n          attachmentName: key\n        },\n        binary: {\n          [\"attachment\"]: item.binary[key]\n        }\n      });\n    }\n  }\n}\n\nreturn results;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "9594d9ef-a7b3-4c92-b137-85e44bc7bd0e",
      "name": "get Products",
      "type": "n8n-nodes-base.set",
      "position": [
        6912,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "77c75b9c-b29d-489d-b340-2531eda02bb3",
              "name": "products",
              "type": "array",
              "value": "={{ $('Products').first().json.content.products }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1f0bc0cc-0813-4ca2-9aad-0033c809a2e6",
      "name": "Execute Workflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        9552,
        784
      ],
      "parameters": {
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        },
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "1PVo1WneDnBPX8l3",
          "cachedResultName": "Klippa - add to cart"
        },
        "workflowInputs": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "f6317816-efa3-494b-a8d8-74bd5ef768f4",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        9744,
        784
      ],
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "2d08b11b-d4cb-41de-a8ed-4962ba1a8b8f",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        9136,
        544
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.1
    },
    {
      "id": "a4480866-98a0-45ad-94d0-0d806cb79a46",
      "name": "place Order",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        14464,
        576
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/carts/{{ $('set Quote Id').first().json.quote_id }}/order",
        "method": "PUT",
        "options": {},
        "jsonBody": "={\n    \"paymentMethod\": {\n        \"method\": \"companycredit\"\n    }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.2
    },
    {
      "id": "1d589a8b-fcdb-4f8f-940a-41ac846ff0e0",
      "name": "filter Emailadresses",
      "type": "n8n-nodes-base.code",
      "position": [
        2240,
        1168
      ],
      "parameters": {
        "jsCode": "const content = $json.content;\nconst emails = $input.first().json.content.email ?? [];\nconst filteredEmails = emails.filter(email => !email.toLowerCase().includes('@example.com'));\nconst updatedContent = {\n    ...content,\n    email: filteredEmails\n};\n\nreturn [{\n    json: {\n        content: updatedContent\n    }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "af09e1cb-7445-4282-8d42-21dc46c2f045",
      "name": "remove SCH",
      "type": "n8n-nodes-base.code",
      "position": [
        3184,
        848
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  // veilige clone (ook van json) zodat we het origineel niet muteren\n  const newItem = { ...item, json: { ...item.json } };\n\n  const content = newItem.json.content || {};\n  const srcProducts = Array.isArray(content.products) ? content.products : [];\n\n  // bewerk elke productregel\n  const newProducts = srcProducts.map(p => {\n    const product = { ...p };\n    let num = product.articlenumber;\n\n    if (typeof num === 'string') {\n      // trim en case-insensitive check\n      const trimmed = num.trim();\n      if (trimmed.toUpperCase().startsWith('SCH')) {\n        // verwijder alleen de eerste 3 tekens (de 'SCH' prefix)\n        product.articlenumber = trimmed.substring(3);\n      } else {\n        product.articlenumber = trimmed; // normaliseer zonder prefix\n      }\n    }\n\n    return product;\n  });\n\n  // zet terug in content.products\n  newItem.json.content = { ...content, products: newProducts };\n\n  return newItem;\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "c5239a47-4d29-41bf-a109-cdfc22bbeb6b",
      "name": "No Operation, do nothing4",
      "type": "n8n-nodes-base.noOp",
      "position": [
        10432,
        1088
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "52a5fb8a-0462-4e97-a1c0-da6e8fc0bb79",
      "name": "set Feedback configurable",
      "type": "n8n-nodes-base.set",
      "position": [
        8672,
        1072
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7d430e2c-bc0f-4f7a-a718-e0f4a0e21a51",
              "name": "message",
              "type": "string",
              "value": "=No product found with sku: \n{{ $json.articlenumber }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a1d68621-d2ca-44ee-9ebc-67dc85dab044",
      "name": "get Order by PO number",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3984,
        928
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/orders?searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[filterGroups][0][filters][0][field]=custom_reference_number&searchCriteria[filterGroups][0][filters][0][value]={{ $json.content.po_number }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "545040e0-790e-4904-8d73-6c05c952459d",
      "name": "Set empty PO number message1",
      "type": "n8n-nodes-base.set",
      "position": [
        4464,
        1664
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "50596fcc-fd14-4554-88a7-919c9826b68b",
              "name": "message",
              "type": "string",
              "value": "PO number already exists in Magento"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "81fcce51-167a-4f2b-8c55-d6d5a8e15614",
      "name": "IF PO number not exists",
      "type": "n8n-nodes-base.if",
      "position": [
        4192,
        928
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "83de1941-269f-46db-82e4-fd4945887cb6",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $json.total_count }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d19b78d3-428d-471a-aa6f-be6a3b48e7f3",
      "name": "Microsoft Outlook Trigger",
      "type": "n8n-nodes-base.microsoftOutlookTrigger",
      "position": [
        -80,
        832
      ],
      "parameters": {
        "output": "raw",
        "filters": {
          "foldersToInclude": [
            "AAMkADc5ZDM1NjExLWUyMmEtNGFjNS1iZjQ0LWQ1NDIzNjIwM2JhYgAuAAAAAADhdXAyhBkYQ7FZ5j1Q8N6TAQDWbfNIjjgwSYEfigJmM_e_AAAAAAEMAAA="
          ]
        },
        "options": {
          "downloadAttachments": true
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8aeda9ee-3bb7-4bf6-bd10-fa255e55fa2a",
      "name": "set Text",
      "type": "n8n-nodes-base.set",
      "position": [
        128,
        832
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fa169825-4f61-4185-8382-1e7760219241",
              "name": "text",
              "type": "string",
              "value": "={{ $json.body.content }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "fe530607-22d6-47e9-8496-136b67939e6d",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1648,
        1168
      ],
      "parameters": {
        "text": "=Please extract the following information from the text as valid json.:\n\n\"email\" (array with all email adresses found. Add ALL found email addresses!)\n\"po_number\"\n\"express\" (true or false when express shipping is requested)\n\n\"address\" (skip any address from ourselves, ...), which contains the following fields:\n\"first_name\" (dash if empty)\n\"last_name\" (dash if empty)\n\"company_name\"\n\"street\" (without housenumber)\n\"housenumber\"\n\"zipcode\"\n\"city\" (make sure this city really exist in the country that is also extracted)\n\"country_code\": 2 digit country code\n\"phone_number\": can only contains a + in the beginning, dashes or spaces. Remove any other characters!\n\nAn array with \"products\" that contains:\narticlenumber: Remove any addition Extract the line items from the following purchase order text, making sure to include the full article number exactly as it appears in the text \u2014 including any leading characters or digits. Do not omit or alter any part of the article number. \nquantity\nprice\n\nAfter all the products, add ALL extra fields and their values in their original language when found within an object \"extra_fields\"!\n\nThis is a template of how the output should be:\n{\n  \"email\": [\n    \"\"\n  ],\n  \"po_number\": \"\",\n  \"express\": true,\n  \"address\": {\n    \"first_name\": \"\",\n    \"last_name\": \"\",\n    \"company_name\": \"\",\n    \"street\": \"\",\n    \"housenumber\": \"\",\n    \"zipcode\": \"\",\n    \"city\": \"\",\n    \"country_code\": \"\",\n    \"phone_number\": \"\"\n  },\n  \"products\": [\n    {\n      \"articlenumber\": \"\",\n      \"condition\": \"\",\n      \"quantity\": 2,\n      \"price\": 1455.75\n    }\n  ],\n  \"extra_fields\": {  }\n}\n\nThis is the information:\n{{ $json.info }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "4dc910d3-4288-4891-b188-b8a2782cf930",
      "name": "Move a message",
      "type": "n8n-nodes-base.microsoftOutlook",
      "position": [
        14912,
        576
      ],
      "parameters": {
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "AAMkADc5ZDM1NjExLWUyMmEtNGFjNS1iZjQ0LWQ1NDIzNjIwM2JhYgAuAAAAAADhdXAyhBkYQ7FZ5j1Q8N6TAQDWbfNIjjgwSYEfigJmM_e_AAC4Oo2sAAA=",
          "cachedResultUrl": "https://outlook.office365.com/mail/AAMkADc5ZDM1NjExLWUyMmEtNGFjNS1iZjQ0LWQ1NDIzNjIwM2JhYgAuAAAAAADhdXAyhBkYQ7FZ5j1Q8N6TAQDWbfNIjjgwSYEfigJmM_e_AAC4Oo2sAAA%3D",
          "cachedResultName": "processed orders"
        },
        "messageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Email combine').first().json.id }}"
        },
        "operation": "move"
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "5de7e170-6b63-445f-af9c-2a5e9b8b2cc3",
      "name": "No Operation, do nothing2",
      "type": "n8n-nodes-base.noOp",
      "position": [
        5408,
        1728
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f702cbea-aa85-45c0-a7bf-630971cf6286",
      "name": "get Customer",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        5168,
        928
      ],
      "parameters": {
        "url": "=https://www.example.com/rest/V1/customers/search?searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[filterGroups][0][filters][0][field]=email&searchCriteria[filterGroups][0][filters][0][value]={{ $json.email.trim() }}&searchCriteria[filterGroups][1][filters][0][conditionType]=eq\n&searchCriteria[filterGroups][1][filters][0][field]=website_id\n&searchCriteria[filterGroups][1][filters][0][value]=1&searchCriteria[pageSize]=1",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "magento2Api"
      },
      "credentials": {
        "magento2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0fb6677d-e26d-4373-b2a4-318950742b8e",
      "name": "If Customer",
      "type": "n8n-nodes-base.if",
      "position": [
        5344,
        928
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "28934991-2b90-46fe-873d-58ba9303fcd0",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $('get Customer').first().json.total_count }}",
              "rightValue": 1
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "94f319fe-7e02-47b7-b6fc-07f882fb51f3",
      "name": "Products",
      "type": "n8n-nodes-base.noOp",
      "position": [
        3456,
        992
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "5d76163c-e4e0-4701-b7f4-fce91e26793f",
      "name": "Sticky Note - Trigger & Input",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -16
      ],
      "parameters": {
        "color": 4,
        "width": 1568,
        "height": 2592,
        "content": "# \ud83d\udce9 1. Trigger & Input\n## This section retrieves emails and extracts PDF attachments.\n\nMonitors the Outlook mailbox for incoming purchase order emails.\nAutomatically downloads PDF attachments.\nCombines email body text and PDF data into a single data stream.\nPrepares raw order information for AI-based parsing"
      },
      "typeVersion": 1
    },
    {
      "id": "d92ce0d3-e32a-42f2-9203-0d271163584f",
      "name": "Sticky Note - AI Parsing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        -16
      ],
      "parameters": {
        "color": 6,
        "width": 2960,
        "height": 1584,
        "content": "# \ud83d\udcdd AI Parsing & Normalisation & Checks\n## Parse PDF with AI, clean product data and filter emails.\n\nSends email and PDF content to Azure OpenAI for parsing.\nExtracts key fields such as PO number, customer data, and product list into structured JSON.\nCleans product article numbers (e.g. removing SCH prefixes or unwanted suffixes).\nFilters out invalid or irrelevant email addresses from the extracted data.\nEnsures no duplicate or invalid orders are created."
      },
      "typeVersion": 1
    },
    {
      "id": "faaae4e9-a753-43ab-b158-4a7cba1fec9d",
      "name": "Sticky Note - Customer Validation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4448,
        -16
      ],
      "parameters": {
        "color": 2,
        "width": 1664,
        "height": 1584,
        "content": "# \ud83d\udc64 Customer Validation\n## Check if customer exists, validate addresses and company credit.\n\nSearches for the customer in Adobe Commerce using the extracted email address.\nVerifies if the customer account exists in the webshop.\nRetrieves and checks the default shipping address.\nProvides feedback if no valid customer or default address is found."
      },
      "typeVersion": 1
    },
    {
      "id": "ba367cd6-adc9-40ea-b541-1f971c4568ab",
      "name": "Sticky Note - Cart Creation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6160,
        -16
      ],
      "parameters": {
        "color": 5,
        "width": 5008,
        "height": 1584,
        "content": "# \ud83d\uded2 Cart Creation & Products\n## Create cart, add products, remove duplicates and prepare order.\n\nCreates a new empty shopping cart (quote) for the validated customer.\nClears any existing items from the customer\u2019s cart.\nIterates over each parsed product and adds it to the cart.\nValidates SKU and availability in Adobe Commerce.\nLogs feedback if products are missing or cannot be added."
      },
      "typeVersion": 1
    },
    {
      "id": "52c35a3c-a624-45c3-8c88-bf1985665879",
      "name": "Sticky Note - Shipping & Billing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        11184,
        -16
      ],
      "parameters": {
        "color": 6,
        "width": 1776,
        "height": 1584,
        "content": "# \ud83d\ude9a Shipping & Billing\n## Set billing and shipping addresses, estimate methods, apply standard/express.\n\nSets the billing address in the cart.\nEstimates available shipping methods.\nApplies either the standard or express shipping method based on extracted order data.\nEnsures shipping information is correctly linked to the quote."
      },
      "typeVersion": 1
    },
    {
      "id": "de3a1ffb-d421-4218-8b4b-c4df4f334397",
      "name": "Sticky Note - Finalize Order",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        12992,
        -16
      ],
      "parameters": {
        "color": 4,
        "width": 2528,
        "height": 1584,
        "content": "# \u2705 Finalize Order\n## Set PO number, add order comments, validate payment and place order.\n\nValidates and sets the Purchase Order number in the cart.\nAdds an internal order comment for traceability.\nRetrieves available payment methods and checks for Company Credit.\nPlaces the final order in Adobe Commerce using Company Credit.\nMoves the processed email into the \u201cProcessed Orders\u201d folder."
      },
      "typeVersion": 1
    },
    {
      "id": "d0d18335-f840-498e-be2b-edb3e8b2bdae",
      "name": "Sticky Note - Error Handling1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        1600
      ],
      "parameters": {
        "color": 3,
        "width": 14080,
        "height": 976,
        "content": "# \u26a0\ufe0f Error Handling\n## Fallback nodes to catch and log errors, feedback messages, and move processed email.\n\nStops the workflow gracefully if critical data is missing.\nProvides clear feedback messages (e.g. \u201cNo customer found\u201d, \u201cNo PO number\u201d, \u201cCompany Credit not available\u201d).\nSends structured error output for notifications or monitoring."
      },
      "typeVersion": 1
    },
    {
      "id": "a9745dc5-5bcf-4414-9cb0-7e035859c792",
      "name": "Azure OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        1648,
        1408
      ],
      "parameters": {
        "model": "model-router",
        "options": {
          "responseFormat": "json_object"
        }
      },
      "credentials": {
        "azureOpenAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5513ca36-a813-4136-8c4e-e4dda5fae7a9",
      "name": "Loop until existing customer found",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        4912,
        912
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "389b4f77-2cc6-48d1-b547-7910903aaef4",
      "name": "If configurable product found",
      "type": "n8n-nodes-base.if",
      "position": [
        8160,
        688
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7be16b31-66d4-402e-801d-b8ad9ce4624e",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $json.total_count }}",
              "rightValue": 1
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "754c7b4c-4f07-481d-9108-186a6e588c5e",
      "name": "Prepare sku & quote",
      "type": "n8n-nodes-base.set",
      "position": [
        8480,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ecb9f0e5-4452-49f6-b224-7394ecd097d4",
              "name": "sku",
              "type": "string",
              "value": "={{ $json.items[0].sku }}"
            },
            {
              "id": "6714cc81-bfa6-450d-a202-759485205490",
              "name": "quote_id",
              "type": "string",
              "value": "={{ $('set Quote Id').first().json.quote_id }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "783ffc5c-8107-47c7-a703-6d4bc6550c3c",
      "name": "If product in cart",
      "type": "n8n-nodes-base.if",
      "position": [
        9552,
        544
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "10555ad1-148f-496b-9198-dd69b1cfc54a",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.item_id }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "01ee82fd-75f5-4471-b0b3-4523ce827ce0",
      "name": "Loop over products",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        8912,
        672
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "d33241a7-592e-4386-8dd7-787d41d5744c",
      "name": "Combine processed skus",
      "type": "n8n-nodes-base.code",
      "position": [
        10352,
        688
      ],
      "parameters": {
        "jsCode": "const output = items.map(item => {\n  const sku = item.json.items[0].sku;\n  const price = item.json.price;\n  return `\\n${sku}: \u20ac${price}`;\n});\n\nreturn [\n  {\n    json: {\n      combined: output.join(\", \")\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cf0fd160-d2a5-4f71-bca6-8fab70d4a734",
      "name": "Combine failed skus",
      "type": "n8n-nodes-base.code",
      "position": [
        10352,
        832
      ],
      "parameters": {
        "jsCode": "const output = items.map(item => {\n  const sku = item.json.items[0].sku;\n  const price = item.json.price;\n  return `\\n${sku}: \u20ac${price}`;\n});\n\nreturn [\n  {\n    json: {\n      combined: output.join(\", \")\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "92cfc8a1-d480-4ddb-8e52-9fde4ad458b2",
      "name": "set Feedback failed",
      "type": "n8n-nodes-base.set",
      "position": [
        10560,
        832
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7d430e2c-bc0f-4f7a-a718-e0f4a0e21a51",
              "name": "message",
              "type": "string",
              "value": "=No product with specified price found, or requested stock is not available for sku(s):\n{{ $json.combined }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "aa70d781-e980-4072-86b4-13e57028d4c4",
      "name": "set Feedback processed",
      "type": "n8n-nodes-base.set",
      "position": [
        10560,
        688
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7d430e2c-bc0f-4f7a-a718-e0f4a0e21a51",
              "name": "message",
              "type": "string",
              "value": "=The following product(s) are added to the order:\n{{ $json.combined }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c61ed836-43ce-4f36-aa1a-d35fb88a60f6",
      "name": "Combine feedback",
      "type": "n8n-nodes-base.code",
      "position": [
        10752,
        832
      ],
      "parameters": {
        "jsCode": "let input1 = null;\nlet input2 = null;\nlet input3 = null;\n\nif ($node[\"set Feedback failed\"].runIndex !== -1 || $node[\"set Feedback configurable\"].runIndex !== -1) {\n  \n  if ($node[\"set Feedback processed\"].runIndex !== -1) {\n    input1 = $node[\"set Feedback processed\"].json.message;\n  }\n  \n  if ($node[\"set Feedback failed\"].runIndex !== -1) {\n    input2 = $node[\"set Feedback failed\"].json.message;\n  }\n  \n  if ($node[\"set Feedback configurable\"].runIndex !== -1) {\n    input3 = $node[\"set Feedback configurable\"].json.message;\n  }\n  \n  const messages = [input1, input2, input3].filter(Boolean);\n  \n  return [\n    {\n      json: {\n        message: messages.join(\"\\n\\n\")\n      }\n    }\n  ];\n}\nr

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow automatically converts PDF purchase orders received by email into completed sales orders in Adobe Commerce, using AI to read the document and Company Credit as the payment method. It saves procurement teams and operations staff hours of manual data entry while ensuring accurate order creation and reference tracking. The key step is the AI agent extracting line items and customer details from the PDF before passing them to Adobe Commerce via API calls.

Use it when purchase orders arrive as unstructured PDFs and you need reliable conversion into Magento 2 orders; avoid it for high-volume environments requiring strict compliance or when orders need immediate payment capture. Common variations include swapping the email trigger for a form submission or adding approval steps before order creation.

About this workflow

This n8n template demonstrates how to automatically process PDF purchase orders received via email and convert them into sales orders in Adobe Commerce (Magento 2) using Company Credit as the payment method.

Source: https://n8n.io/workflows/8388/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

How it Works

Memory Buffer Window, Agent, Output Parser Structured +9
AI & RAG

My workflow 53. Uses formTrigger, httpRequest, lmChatOpenAi, form. Event-driven trigger; 74 nodes.

Form Trigger, HTTP Request, OpenAI Chat +15
AI & RAG

1_4_Core_Node. Uses stopAndError, compression, xml, crypto. Event-driven trigger; 63 nodes.

Stop And Error, Compression, XML +7
AI & RAG

PixelSensei(ZH). Uses agent, outputParserStructured, formTrigger, lmChatOpenAi. Event-driven trigger; 55 nodes.

Agent, Output Parser Structured, Form Trigger +4
AI & RAG

🧠 Automate end-to-end SEO blog creation and WordPress publishing using a GPT-5 multi-agent workflow with real-time research, metadata generation, and optional featured images.

Output Parser Structured, HTTP Request, OpenAI +10