{
  "name": "KyndredAI · Tiendanube orden → Sheets + WhatsApp",
  "nodes": [
    {
      "parameters": {
        "content": "# 🔷 KyndredAI · Tiendanube orden → Sheets + WhatsApp\n\nCuando entra una **orden nueva** en Tiendanube, trae los datos, la **registra en Google Sheets** y le manda al cliente un **WhatsApp de confirmación**.\n\n**Cómo funciona:** Webhook (order/created) → trae la orden de la API de Tiendanube → normaliza → Google Sheets → WhatsApp al cliente.\n\n**Necesitás:** una app de Tiendanube con su **Access Token** + Google Sheets + acceso a la **WhatsApp Cloud API** (Meta) o tu proveedor de WhatsApp.\n\n⚠️ Tiendanube manda solo el `id` de la orden; por eso después traemos la orden completa de la API.\n\nself-hosted o cloud · kyndredai.com",
        "height": 380,
        "width": 880,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        432,
        80
      ],
      "id": "ab2d2792-4dfb-4cf8-b1cb-2e78672b5797",
      "name": "README"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "tiendanube-orden",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        48,
        512
      ],
      "id": "2b699d2f-cbae-4788-8656-bc79d8f3bdae",
      "name": "Recibir orden (Webhook)",
      "webhookId": "c2b2c2d2-2222-4222-8222-c22222222222"
    },
    {
      "parameters": {
        "url": "=https://api.tiendanube.com/v1/{{ $json.body.store_id }}/orders/{{ $json.body.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        320,
        512
      ],
      "id": "76b86dec-ba04-4008-ac22-0927f4de9d06",
      "name": "Traer orden (Tiendanube)",
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c4000001-0000-4000-8000-000000000001",
              "name": "orden",
              "value": "={{ $json.number }}",
              "type": "string"
            },
            {
              "id": "c4000002-0000-4000-8000-000000000002",
              "name": "cliente",
              "value": "={{ $json.contact_name }}",
              "type": "string"
            },
            {
              "id": "c4000003-0000-4000-8000-000000000003",
              "name": "telefono",
              "value": "={{ $json.contact_phone }}",
              "type": "string"
            },
            {
              "id": "c4000004-0000-4000-8000-000000000004",
              "name": "total",
              "value": "={{ $json.total }}",
              "type": "string"
            },
            {
              "id": "c4000005-0000-4000-8000-000000000005",
              "name": "estado",
              "value": "={{ $json.status }}",
              "type": "string"
            },
            {
              "id": "c4000006-0000-4000-8000-000000000006",
              "name": "fecha",
              "value": "={{ $now.toFormat('yyyy-LL-dd HH:mm') }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        608,
        512
      ],
      "id": "e2b8d369-9cbc-4d27-9f40-2df68b1aabc6",
      "name": "Datos de la orden"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": ""
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": ""
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        880,
        512
      ],
      "id": "fadd3cf0-ecab-40c7-bc7b-b2c0f3d2cd52",
      "name": "Guardar en Sheets",
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/TU_PHONE_NUMBER_ID/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"messaging_product\": \"whatsapp\",\n  \"to\": \"{{ $json.telefono }}\",\n  \"type\": \"text\",\n  \"text\": {\n    \"body\": \"¡Hola {{ $json.cliente }}! Recibimos tu pedido #{{ $json.orden }} por $ {{ $json.total }}. Te avisamos cuando salga el envío. ¡Gracias por tu compra!\"\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1152,
        512
      ],
      "id": "f31b152b-b5c1-437d-b37a-ee5c324516cc",
      "name": "WhatsApp al cliente",
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1408,
        512
      ],
      "id": "4a7a2e1d-a29b-438e-ba0e-63e33a511f6d",
      "name": "Listo"
    },
    {
      "parameters": {
        "content": "## ① Tiendanube\n\n1. Creá una app en tu panel de Tiendanube y conseguí el **Access Token**.\n2. Suscribí el webhook **order/created** a la URL de este nodo.\n3. En *Traer orden* → Credential → Header Auth → Name `Authentication`, Value `bearer TU_TOKEN`. Agregá también el header `User-Agent` con tu app/email si la API lo pide.",
        "height": 308,
        "width": 320,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        224,
        704
      ],
      "id": "4097c093-26e2-4592-b600-eed02c884da4",
      "name": "Setup 1"
    },
    {
      "parameters": {
        "content": "## ② Google Sheets\n\n*Guardar en Sheets* → Credential → conectá tu Google → elegí planilla + pestaña, mapeo **Map Automatically**.\n\nEncabezados sugeridos:\n**orden · cliente · telefono · total · estado · fecha**",
        "height": 252,
        "width": 300,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        784,
        704
      ],
      "id": "00e01949-7a4d-4efa-9ae7-a438e9f7bf31",
      "name": "Setup 2"
    },
    {
      "parameters": {
        "content": "## ③ WhatsApp\n\nUsa la **WhatsApp Cloud API** (Meta):\n1. Reemplazá `TU_PHONE_NUMBER_ID` en la URL.\n2. Credential → Header Auth → Name `Authorization`, Value `Bearer TU_TOKEN`.\n3. El `to` debe ir en formato internacional (ej. 5491122334455).\n\n💡 ¿Usás otro proveedor (Twilio, etc.)? Cambiá URL + body por el suyo.",
        "height": 324,
        "width": 416,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        704
      ],
      "id": "55f901b7-000d-4db7-9bfe-427f6ffc4c97",
      "name": "Setup 3"
    }
  ],
  "connections": {
    "Recibir orden (Webhook)": {
      "main": [
        [
          {
            "node": "Traer orden (Tiendanube)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Traer orden (Tiendanube)": {
      "main": [
        [
          {
            "node": "Datos de la orden",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Datos de la orden": {
      "main": [
        [
          {
            "node": "Guardar en Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Guardar en Sheets": {
      "main": [
        [
          {
            "node": "WhatsApp al cliente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp al cliente": {
      "main": [
        [
          {
            "node": "Listo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": []
}
