{
  "name": "Meta Lead Ads to AWeber (template)",
  "nodes": [
    {
      "parameters": {
        "content": "## Meta Lead Ads to AWeber\nSanitised template from iBoyDroid: https://iboydroid.com/systems/meta-lead-ads-to-aweber/ (setup, every error and its fix, cost, and what to change next).\n\n**One-time setup**\n1. Open **Meta Lead Ads Trigger** and create the Facebook Lead Ads credential with the App ID and App Secret of your own Meta app (Business type, product Facebook Login for Business). In the Meta app, add the redirect URL the n8n credential window shows (on n8n Cloud that is https://oauth.n8n.cloud/oauth2/callback) to Valid OAuth Redirect URIs, add n8n.cloud to App Domains, make sure every permission n8n requests is \"Ready for testing\" in the use case, then pick your Page and Form.\n2. Create an **OAuth2 API** credential for AWeber (Authorization Code, auth URL `https://auth.aweber.com/oauth2/authorize`, token URL `https://auth.aweber.com/oauth2/token`, scope `account.read list.read list.write subscriber.read subscriber.write`, Authentication = Body) with the Client ID and Secret of an app created at labs.aweber.com. Select it in every HTTP node.\n3. Run the helper row below once, paste your account id and list id into **Map Lead Fields**, then delete the helper row.\n4. In **Map Lead Fields**, replace the two custom question keys (`monthly_ad_budget?`, `what_best_describes_your_business?`) with the keys of your own form: send a test lead and read `data`. Meta derives the key from the question text, so re-check after any form edit.\n5. In **Send Confirmation**, set your Telegram credential and chat id (or delete the node). Parse Mode is HTML and every value is escaped; keep it that way.\n6. Workflow settings: Save failed production executions = Save; Error workflow = the imported \"Meta Lead Ads to AWeber Error\" workflow. Manual runs never fire an error workflow, so test it with a real production failure.\n7. Save, then Publish. Send a test lead with Meta's Lead Ads Testing Tool. AWeber refuses the tool's dummy address (403), so finish with Preview form and a real email. The Meta app must be Live for real leads.",
        "height": 640,
        "width": 1040,
        "color": 4
      },
      "id": "9d887f0b-869a-4b45-b3c4-4510c1a09317",
      "name": "Setup Notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        464,
        32
      ]
    },
    {
      "parameters": {
        "page": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "form": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "options": {}
      },
      "id": "1833e820-dea2-4326-859e-74ac12ce4033",
      "name": "Meta Lead Ads Trigger",
      "type": "n8n-nodes-base.facebookLeadAdsTrigger",
      "typeVersion": 1,
      "position": [
        512,
        352
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "39830e19-02e7-4c48-bccf-9cd16a6987d0",
              "name": "aweber_account_id",
              "value": "REPLACE_WITH_AWEBER_ACCOUNT_ID",
              "type": "string"
            },
            {
              "id": "ab2fe070-6cc0-439a-baea-5ae0b53fb465",
              "name": "aweber_list_id",
              "value": "REPLACE_WITH_AWEBER_LIST_ID",
              "type": "string"
            },
            {
              "id": "e2afc7ee-838d-44d1-ad33-c44e4d70094a",
              "name": "name",
              "value": "={{ $json.data.full_name || [$json.data.first_name, $json.data.last_name].filter(Boolean).join(' ') }}",
              "type": "string"
            },
            {
              "id": "c3eadda2-43ec-4285-9b7e-8138ee8aad08",
              "name": "budget",
              "value": "={{ $json.data['monthly_ad_budget?'] || '' }}",
              "type": "string"
            },
            {
              "id": "ad4c1fe5-0167-4cd0-b8d7-1e3e2efb3176",
              "name": "phone",
              "value": "={{ $json.data.phone_number || '' }}",
              "type": "string"
            },
            {
              "id": "8f88fcd2-02b6-4d91-90c0-3d15ef05f951",
              "name": "business_description",
              "value": "={{ $json.data['what_best_describes_your_business?'] || '' }}",
              "type": "string"
            },
            {
              "id": "c6fd0d22-b4ed-47cc-93ac-0a856e3b85bd",
              "name": "website",
              "value": "={{ $json.data.website || '' }}",
              "type": "string"
            },
            {
              "id": "ebed298e-da70-4e6d-b4f4-79462a3cbf4e",
              "name": "email",
              "value": "={{ $json.data.email || $json.data.work_email || '' }}",
              "type": "string"
            },
            {
              "id": "12c29ac2-14e8-42e8-87ec-75898375fbed",
              "name": "tags",
              "value": "={{ [\"meta-lead-ad\"] }}",
              "type": "array"
            },
            {
              "id": "20ff1715-d950-4a89-9dbf-889540ef6760",
              "name": "ad",
              "value": "={{ $json.ad?.name || $json.adset?.name || '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "20658892-a684-4237-9224-a51257974894",
      "name": "Map Lead Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        736,
        352
      ]
    },
    {
      "parameters": {
        "content": "## Helper: get your AWeber IDs (run once)\nAfter the AWeber credential is selected in both HTTP nodes here, click **Execute workflow** from the manual trigger. The last node lists `account_id`, `list_id`, and `list_name` for every list. Paste the two IDs into **Map Lead Fields**. This row can be deleted afterwards.",
        "height": 300,
        "width": 1160,
        "color": 7
      },
      "id": "0212acd0-4d37-4ff3-9d68-d54208a97c1e",
      "name": "Helper Notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        464,
        608
      ]
    },
    {
      "parameters": {},
      "id": "8fd0fd9d-9d62-4228-b77b-d335d83d61ad",
      "name": "Run Once to Get IDs",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        512,
        752
      ]
    },
    {
      "parameters": {
        "url": "https://api.aweber.com/1.0/accounts",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "options": {}
      },
      "id": "4742f9bc-f497-41ea-929c-ca11caf67c69",
      "name": "Get AWeber Account",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        736,
        752
      ]
    },
    {
      "parameters": {
        "url": "=https://api.aweber.com/1.0/accounts/{{ $json.entries[0].id }}/lists",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "options": {}
      },
      "id": "ba3db306-fd1f-4adc-9182-f210b992f4b5",
      "name": "Get AWeber Lists",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        752
      ]
    },
    {
      "parameters": {
        "jsCode": "const account = $('Get AWeber Account').first().json;\nconst accountId = account.entries && account.entries[0] ? account.entries[0].id : null;\nconst lists = $input.first().json.entries || [];\n\nreturn lists.map((list) => ({\n  json: {\n    account_id: accountId,\n    list_id: list.id,\n    list_name: list.name,\n    unique_list_id: list.unique_list_id,\n  },\n}));"
      },
      "id": "6028d76f-b78e-4d06-b747-1d72313a5e35",
      "name": "Show IDs",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1184,
        752
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.aweber.com/1.0/accounts/{{ $json.aweber_account_id }}/lists/{{ $json.aweber_list_id }}/subscribers",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ email: $json.email, name: $json.name, tags: $json.tags, update_existing: true }) }}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "id": "51405c42-4823-46f4-8de1-19f3f0155b8a",
      "name": "Add to AWeber",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        352
      ]
    },
    {
      "parameters": {
        "chatId": "REPLACE_WITH_TELEGRAM_CHAT_ID",
        "text": "=👌 New Lead Is Here: {{ String($('Map Lead Fields').item.json.name ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n\n👇 More Details:\n- Full Name: {{ String($('Map Lead Fields').item.json.name ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n- Budget: {{ String($('Map Lead Fields').item.json.budget ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n- Phone Number: {{ String($('Map Lead Fields').item.json.phone ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n- Business Description: {{ String($('Map Lead Fields').item.json.business_description ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n- Website: {{ String($('Map Lead Fields').item.json.website ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n- Email: {{ String($('Map Lead Fields').item.json.email ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n\n🖇️ AD Campaign: {{ String($('Map Lead Fields').item.json.ad ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') }}\n\n🕒 Time: {{ $now.toFormat('MM.dd.yyyy HH:mm:ss ZZZZ') }}\n",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1184,
        352
      ],
      "id": "4cd488ea-b7d9-4da8-b487-67540a589000",
      "name": "Send Confirmation"
    }
  ],
  "connections": {
    "Meta Lead Ads Trigger": {
      "main": [
        [
          {
            "node": "Map Lead Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map Lead Fields": {
      "main": [
        [
          {
            "node": "Add to AWeber",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Once to Get IDs": {
      "main": [
        [
          {
            "node": "Get AWeber Account",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get AWeber Account": {
      "main": [
        [
          {
            "node": "Get AWeber Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get AWeber Lists": {
      "main": [
        [
          {
            "node": "Show IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to AWeber": {
      "main": [
        [
          {
            "node": "Send Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1",
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all"
  },
  "active": false
}
