{
  "id": "fiwano-connect-channels",
  "name": "Fiwano \u2014 Connect a Channel via API (WhatsApp / Instagram / Facebook)",
  "nodes": [
    {
      "parameters": {
        "content": "## Connect a Channel via API\n### WhatsApp \u00b7 Instagram \u00b7 Facebook\n\nConnect channels **one at a time**, right from n8n. Each run links one Meta account and returns its **`channel_id`**.\n\nThe workflow has two halves:\n- **\u25b6 Get a setup link \u2192 Generate setup link** \u2014 asks Fiwano for a one-time `setup_url`.\n- **OAuth Callback \u2192 Exchange code** \u2014 after the user authorizes, Meta redirects back here with `?code=\u2026`; *Exchange code* swaps it for a `channel_id` (single-use, valid 5 min) and shows the connected channel in the browser.\n\n### One-time setup\n1. Add your **Fiwano API** credential to both Fiwano nodes \u2014 **Generate setup link** and **Exchange code \u2192 channel**.\n2. Open **OAuth Callback** \u2192 the **Production URL** tab \u2192 copy that URL.\n   *(It's shown even while inactive \u2014 activating doesn't create the URL, it just makes the webhook listen.)*\n3. **Whitelist** that URL with Fiwano (it only redirects to approved URLs):\n   - **Portal:** API Keys \u2192 Allowed Redirect URIs \u2192 add it, **or**\n   - add a **Fiwano \u2192 Redirect URI \u2192 Add** node, set `uriPattern` to the URL, run once.\n4. Paste the same URL into **Generate setup link \u2192 Redirect URI**, and pick a **Channel Type**.\n5. **Activate** the workflow \u2014 now the callback is live to receive Meta's redirect.\n\n### Connect a channel\n1. Run **\u25b6 Get a setup link** and open the returned **`setup_url`** in a browser.\n2. Authorize the Meta account \u2192 you're redirected back, the code is exchanged, and the connected **`channel_id`** is returned. \u2705\n\nRepeat per channel.\n\n**Reconnecting** uses this same flow \u2014 authorize the same Meta account and Fiwano reactivates the existing channel, returning the `channel_id` you already had. There is no separate reconnect step.\n\n**If the user cancels or setup fails**, Meta redirects with `?error=\u2026` instead of `?code=\u2026` (`access_denied` or `setup_failed`, plus a human-readable `message`). This template assumes the happy path; branch on `error` before *Exchange code* if you surface this to end users.\n\n### Webhooks \u2014 now or later?\nIn **Exchange code \u2192 Additional Fields** you can set the channel's **Webhook URL**, **Secret** and **Events** here, so it receives messages the moment it connects. Or leave them empty and let the **Fiwano Trigger**'s *Auto-Setup* wire it \u2014 recommended with the **Universal Auto-Responder** template.\n\nn8n must be publicly reachable. You can also connect channels in the [Fiwano portal](https://fiwano.com).\n\n[Docs](https://fiwano.com/documentation/channels)",
        "height": 1595,
        "width": 460,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        120
      ],
      "id": "cc3d0003-0003-4000-8000-000000000001",
      "name": "About this workflow"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        140,
        320
      ],
      "id": "cc3d0003-0003-4000-8000-000000000002",
      "name": "\u25b6 Get a setup link"
    },
    {
      "parameters": {
        "resource": "channel",
        "operation": "setupUrl",
        "channelType": "whatsapp",
        "redirectUri": ""
      },
      "type": "n8n-nodes-fiwano.fiwano",
      "typeVersion": 1,
      "position": [
        360,
        320
      ],
      "id": "cc3d0003-0003-4000-8000-000000000003",
      "name": "Generate setup link"
    },
    {
      "parameters": {
        "httpMethod": "GET",
        "path": "fiwano-oauth-callback",
        "responseMode": "lastNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        140,
        600
      ],
      "id": "cc3d0003-0003-4000-8000-000000000004",
      "name": "OAuth Callback"
    },
    {
      "parameters": {
        "resource": "channel",
        "operation": "exchangeCode",
        "code": "={{ $json.query.code }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-fiwano.fiwano",
      "typeVersion": 1,
      "position": [
        360,
        600
      ],
      "id": "cc3d0003-0003-4000-8000-000000000005",
      "name": "Exchange code \u2192 channel"
    }
  ],
  "connections": {
    "\u25b6 Get a setup link": {
      "main": [
        [
          {
            "node": "Generate setup link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OAuth Callback": {
      "main": [
        [
          {
            "node": "Exchange code \u2192 channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}