> ## Documentation Index
> Fetch the complete documentation index at: https://docs.migma.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# n8n Integration

> Automate email generation with Migma and n8n - No code required

## Overview

Automate your email workflows using Migma and [n8n](https://n8n.io). Import brands from websites and generate AI-powered emails using simple drag-and-drop nodes.

<Info>
  **What is n8n?** An open-source workflow automation tool with a visual interface. Perfect for connecting APIs without writing code.
</Info>

## Quick Setup

<Steps>
  <Step title="Get Your API Key">
    Go to [Migma Settings → Developers → API Keys](https://migma.ai/settings?tab=api-keys) and create an API key
  </Step>

  <Step title="Add Credentials in n8n">
    In n8n: **Settings → Credentials → Add Credential → Http Bearer Auth**

    Paste your API key and name it "Migma API"
  </Step>
</Steps>

## Key Endpoints

All endpoints use `https://api.migma.ai` as the base URL.

| Endpoint                                      | Method | Description                     |
| --------------------------------------------- | ------ | ------------------------------- |
| `/v1/projects/import`                         | POST   | Import a brand from website URL |
| `/v1/projects/import/{projectId}/status`      | GET    | Check import status             |
| `/v1/projects/{projectId}`                    | GET    | Get project details             |
| `/v1/projects/emails/generate`                | POST   | Generate an email               |
| `/v1/projects/emails/{conversationId}/status` | GET    | Check generation status         |
| `/v1/export/html/{conversationId}`            | GET    | Export as HTML                  |
| `/v1/emails/test/send`                        | POST   | Send test email                 |

<Card title="Full API Reference" icon="book" href="/api-reference/introduction">
  View complete documentation with all parameters and responses
</Card>

## Copy-Paste Workflows

### 1. Import a Brand

Import brand assets from a website URL.

<Accordion title="Import Brand Workflow JSON">
  ```json theme={null}
  {
    "name": "Migma: Import Brand",
    "nodes": [
      {
        "parameters": {},
        "id": "manual-trigger",
        "name": "Start",
        "type": "n8n-nodes-base.manualTrigger",
        "typeVersion": 1,
        "position": [250, 300]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/projects/import",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"urls\": [\"https://yourwebsite.com\"]}",
          "options": {}
        },
        "id": "import-brand",
        "name": "Import Brand",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [450, 300],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      }
    ],
    "connections": {
      "Start": {
        "main": [[{ "node": "Import Brand", "type": "main", "index": 0 }]]
      }
    }
  }
  ```
</Accordion>

**What you get back:**

* `projectId`: Use this to check status
* `status`: Will be "pending" initially
* `domain`: Extracted domain name

### 2. Generate an Email

Generate an AI-powered email for a project.

<Accordion title="Generate Email Workflow JSON">
  ```json theme={null}
  {
    "name": "Migma: Generate Email",
    "nodes": [
      {
        "parameters": {},
        "id": "manual-trigger",
        "name": "Start",
        "type": "n8n-nodes-base.manualTrigger",
        "typeVersion": 1,
        "position": [250, 300]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/projects/emails/generate",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"projectId\": \"YOUR_PROJECT_ID\", \"prompt\": \"Create a welcome email for new subscribers\"}",
          "options": {}
        },
        "id": "generate-email",
        "name": "Generate Email",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [450, 300],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      }
    ],
    "connections": {
      "Start": {
        "main": [[{ "node": "Generate Email", "type": "main", "index": 0 }]]
      }
    }
  }
  ```
</Accordion>

**What you get back:**

* `conversationId`: Use this to check status and export
* `status`: Will be "pending" initially
* `link`: Direct link to view in Migma dashboard

### 3. Export as HTML

Export the generated email as HTML.

<Accordion title="Export HTML Workflow JSON">
  ```json theme={null}
  {
    "name": "Migma: Export HTML",
    "nodes": [
      {
        "parameters": {},
        "id": "manual-trigger",
        "name": "Start",
        "type": "n8n-nodes-base.manualTrigger",
        "typeVersion": 1,
        "position": [250, 300]
      },
      {
        "parameters": {
          "method": "GET",
          "url": "=https://api.migma.ai/v1/export/html/YOUR_CONVERSATION_ID",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "options": {}
        },
        "id": "export-html",
        "name": "Export HTML",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [450, 300],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      }
    ],
    "connections": {
      "Start": {
        "main": [[{ "node": "Export HTML", "type": "main", "index": 0 }]]
      }
    }
  }
  ```
</Accordion>

**What you get back:**

* `files[0].content`: Full HTML content as string
* `files[0].url`: Download URL (valid for 24 hours)
* `files[0].fileSize`: Size in bytes

<Tip>
  Replace `YOUR_CREDENTIAL_ID`, `YOUR_PROJECT_ID`, and `YOUR_CONVERSATION_ID` with your actual values, or use n8n expressions like `{{ $json.data.projectId }}` to pass data between nodes.
</Tip>

## Complete Workflow

Here's a full workflow that imports a brand, waits for completion, generates an email, and exports it:

<Accordion title="Complete Workflow JSON">
  ```json theme={null}
  {
    "name": "Migma: Complete Workflow",
    "nodes": [
      {
        "parameters": {
          "documentId": {
            "__rl": true,
            "value": "1uS3X18r5pqrcZK6iHMI6StQtBaLAZvpavrUhahv_bTE",
            "mode": "list",
            "cachedResultName": "Migma Leads v1",
            "cachedResultUrl": ""
          },
          "sheetName": {
            "__rl": true,
            "value": 1667714778,
            "mode": "list",
            "cachedResultName": "Sheet01",
            "cachedResultUrl": ""
          },
          "options": {}
        },
        "id": "df5ca5e4-3224-42bd-a593-eecfeceaf60f",
        "name": "Read Stores",
        "type": "n8n-nodes-base.googleSheets",
        "typeVersion": 3,
        "position": [
          -1760,
          352
        ]
      },
      {
        "parameters": {
          "options": {}
        },
        "id": "a83ab73f-b6cd-4882-970f-983c93d7b10a",
        "name": "Loop Stores",
        "type": "n8n-nodes-base.splitInBatches",
        "typeVersion": 3,
        "position": [
          -1552,
          352
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/projects/import",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"urls\": [\"{{ $json['Store URL'] }}\"]}",
          "options": {}
        },
        "id": "2a72b8c9-76fd-4ee2-aee6-a9627e6f8a2c",
        "name": "Import Store",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          -1360,
          352
        ],
        "credentials": {
          "httpBearerAuth": {
            "id": "StqUFSi6OmezZlVH",
            "name": "Bearer Auth account"
          }
        }
      },
      {
        "parameters": {
          "amount": 5,
          "unit": "seconds"
        },
        "id": "94310ed1-811c-480a-81cd-50c0b4d3d2d2",
        "name": "Wait",
        "type": "n8n-nodes-base.wait",
        "typeVersion": 1,
        "position": [
          -192,
          560
        ],
        "webhookId": "wait-webhook-gen"
      },
      {
        "parameters": {
          "conditions": {
            "string": [
              {
                "value1": "={{ $json.data.status }}",
                "operation": "equals",
                "value2": "completed"
              }
            ]
          }
        },
        "id": "55ff368a-5dee-479d-aecf-c6f78c7807e4",
        "name": "Is Ready?",
        "type": "n8n-nodes-base.if",
        "typeVersion": 1,
        "position": [
          32,
          560
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/shopify/connect",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"projectId\": \"{{ $json.data.projectId }}\", \"shopifyStoreUrl\": \"{{ $('Loop Stores').item.json['Store URL'] }}\"}",
          "options": {}
        },
        "id": "b5f28477-5b11-49c7-a6c0-51a6605c6a60",
        "name": "Connect Shopify",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          -784,
          128
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/projects/emails/generate",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"projectId\": \"{{ $json.data.projectId }}\", \"prompt\": \"Create a welcome email\", \"webMode\": true}",
          "options": {}
        },
        "id": "db9b18ac-e681-4771-890b-a7516d89aaf2",
        "name": "Generate Email",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          -384,
          64
        ]
      },
      {
        "parameters": {
          "url": "=https://api.migma.ai/v1/projects/emails/{{ $json.data.conversationId }}/status",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "options": {}
        },
        "id": "43a7fc19-604f-48a8-b01b-b564d01db916",
        "name": "Check Generation",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          -176,
          48
        ],
        "credentials": {
          "httpBearerAuth": {
            "id": "StqUFSi6OmezZlVH",
            "name": "Bearer Auth account"
          }
        }
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/emails/test/send",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"conversationId\": \"{{ $json.data.conversationId }}\", \"to\": \"{{ $('Loop Stores').item.json['Store Owner Email'] }}\"}",
          "options": {}
        },
        "id": "7ea88642-5680-49ff-ae09-df719a68f773",
        "name": "Send Test Email",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          608,
          144
        ]
      },
      {
        "parameters": {},
        "type": "n8n-nodes-base.manualTrigger",
        "typeVersion": 1,
        "position": [
          -1920,
          352
        ],
        "id": "bb3666c4-1a2b-4638-8b50-c90e91761c82",
        "name": "When clicking ‘Execute workflow’"
      },
      {
        "parameters": {
          "url": "=https://api.migma.ai/v1/projects/import/{{ $json.data.projectId }}/status",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "options": {}
        },
        "id": "3d6bf6d2-cfd7-4106-b291-a658cd3dc7db",
        "name": "Check Import Status1",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          -1168,
          352
        ],
        "credentials": {
          "httpBearerAuth": {
            "id": "StqUFSi6OmezZlVH",
            "name": "Bearer Auth account"
          }
        }
      },
      {
        "parameters": {
          "conditions": {
            "string": [
              {
                "value1": "={{ $json.data.status }}",
                "operation": "equals",
                "value2": "active"
              }
            ]
          }
        },
        "id": "8cd0a55d-23fa-47d7-a42c-4e3377f587c9",
        "name": "Is Complete?1",
        "type": "n8n-nodes-base.if",
        "typeVersion": 1,
        "position": [
          -992,
          352
        ]
      },
      {
        "parameters": {
          "amount": 10
        },
        "type": "n8n-nodes-base.wait",
        "typeVersion": 1.1,
        "position": [
          -784,
          368
        ],
        "id": "5930e29f-c31b-4f8c-a5b9-6595df8a3e41",
        "name": "Wait1",
        "webhookId": "318bf499-3ab0-4862-979e-7ae8f7555e66"
      }
    ],
    "pinData": {},
    "connections": {
      "Read Stores": {
        "main": [
          [
            {
              "node": "Loop Stores",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Loop Stores": {
        "main": [
          [
            {
              "node": "Import Store",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "Import Store",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Import Store": {
        "main": [
          [
            {
              "node": "Check Import Status1",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Wait": {
        "main": [
          [
            {
              "node": "Is Ready?",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Is Ready?": {
        "main": [
          [
            {
              "node": "Send Test Email",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "Wait",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Connect Shopify": {
        "main": [
          [
            {
              "node": "Generate Email",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Generate Email": {
        "main": [
          [
            {
              "node": "Check Generation",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Check Generation": {
        "main": [
          [
            {
              "node": "Is Ready?",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Send Test Email": {
        "main": [
          [
            {
              "node": "Loop Stores",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "When clicking ‘Execute workflow’": {
        "main": [
          [
            {
              "node": "Read Stores",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Check Import Status1": {
        "main": [
          [
            {
              "node": "Is Complete?1",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Is Complete?1": {
        "main": [
          [
            {
              "node": "Connect Shopify",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "Wait1",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Wait1": {
        "main": [
          [
            {
              "node": "Check Import Status1",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    },
    "active": false,
    "settings": {
      "executionOrder": "v1"
    },
    "versionId": "52001030-f518-4ec1-9ecb-ef3adc46bf07",
    "meta": {
      "instanceId": "2d68fadaa6ab455961c0fbd849b7b2cf998bc0f9d88f3977fe8e22efddd544b8"
    },
    "id": "Gk1gFIZGdAKIJ7oo",
    "tags": []
  }
  ```
</Accordion>

This workflow:

1. Imports a brand
2. Waits and checks if import is complete (loops until done)
3. Generates an email
4. Waits and checks if generation is complete (loops until done)
5. Exports the final HTML

## Advanced Use Cases

### Shopify Multi-Store Automation

For processing multiple Shopify stores from a spreadsheet, see this advanced workflow:

<Steps>
  <Step title="Prepare Your Data">
    Create a Google Sheet with columns: `Store URL`, `Store Owner Email`, `Store Name`
  </Step>

  <Step title="Read from Sheet">
    Use n8n's Google Sheets node to read all stores
  </Step>

  <Step title="Loop Through Stores">
    Use "Split in Batches" node to process each store one at a time
  </Step>

  <Step title="For Each Store">
    1. Import brand: `POST /v1/projects/import`
    2. Connect Shopify: `POST /v1/shopify/connect`
    3. Generate email: `POST /v1/projects/emails/generate`
    4. Send test email: `POST /v1/emails/test/send`
  </Step>
</Steps>

<Accordion title="Shopify Multi-Store Workflow JSON">
  ```json theme={null}
  {
    "name": "Migma: Shopify Multi-Store",
    "nodes": [
      {
        "parameters": {
          "documentId": "YOUR_GOOGLE_SHEET_ID",
          "sheetName": "Sheet1",
          "options": {}
        },
        "id": "read-sheet",
        "name": "Read Stores",
        "type": "n8n-nodes-base.googleSheets",
        "typeVersion": 3,
        "position": [250, 300],
        "credentials": {
          "googleSheetsOAuth2Api": {
            "id": "YOUR_GOOGLE_CREDENTIAL_ID",
            "name": "Google Sheets"
          }
        }
      },
      {
        "parameters": {
          "batchSize": 1,
          "options": {}
        },
        "id": "loop",
        "name": "Loop Stores",
        "type": "n8n-nodes-base.splitInBatches",
        "typeVersion": 3,
        "position": [450, 300]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/projects/import",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"urls\": [\"{{ $json['Store URL'] }}\"]}",
          "options": {}
        },
        "id": "import-store",
        "name": "Import Store",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [650, 300],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      },
      {
        "parameters": {
          "amount": 10,
          "unit": "seconds"
        },
        "id": "wait",
        "name": "Wait",
        "type": "n8n-nodes-base.wait",
        "typeVersion": 1,
        "position": [850, 300],
        "webhookId": "wait-webhook"
      },
      {
        "parameters": {
          "method": "GET",
          "url": "=https://api.migma.ai/v1/projects/import/{{ $json.data.projectId }}/status",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "options": {}
        },
        "id": "check-status",
        "name": "Check Status",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [1050, 300],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      },
      {
        "parameters": {
          "conditions": {
            "string": [
              {
                "value1": "={{ $json.data.status }}",
                "operation": "equals",
                "value2": "active"
              }
            ]
          }
        },
        "id": "is-ready",
        "name": "Is Ready?",
        "type": "n8n-nodes-base.if",
        "typeVersion": 1,
        "position": [1250, 300]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/shopify/connect",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"projectId\": \"{{ $json.data.projectId }}\", \"shopifyStoreUrl\": \"{{ $('Loop Stores').item.json['Store URL'] }}\"}",
          "options": {}
        },
        "id": "connect-shopify",
        "name": "Connect Shopify",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [1450, 200],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/projects/emails/generate",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"projectId\": \"{{ $json.data.projectId }}\", \"prompt\": \"Create a welcome email\", \"webMode\": true}",
          "options": {}
        },
        "id": "generate-email",
        "name": "Generate Email",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [1650, 200],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      },
      {
        "parameters": {
          "amount": 5,
          "unit": "seconds"
        },
        "id": "wait-gen",
        "name": "Wait",
        "type": "n8n-nodes-base.wait",
        "typeVersion": 1,
        "position": [1850, 200],
        "webhookId": "wait-webhook-gen"
      },
      {
        "parameters": {
          "method": "GET",
          "url": "=https://api.migma.ai/v1/projects/emails/{{ $json.data.conversationId }}/status",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "options": {}
        },
        "id": "check-gen",
        "name": "Check Generation",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [2050, 200],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      },
      {
        "parameters": {
          "conditions": {
            "string": [
              {
                "value1": "={{ $json.data.status }}",
                "operation": "equals",
                "value2": "completed"
              }
            ]
          }
        },
        "id": "is-gen-ready",
        "name": "Is Ready?",
        "type": "n8n-nodes-base.if",
        "typeVersion": 1,
        "position": [2250, 200]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.migma.ai/v1/emails/test/send",
          "authentication": "genericCredentialType",
          "genericAuthType": "httpBearerAuth",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\"conversationId\": \"{{ $json.data.conversationId }}\", \"to\": \"{{ $('Loop Stores').item.json['Store Owner Email'] }}\"}",
          "options": {}
        },
        "id": "send-email",
        "name": "Send Test Email",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [2450, 100],
        "credentials": {
          "httpBearerAuth": {
            "id": "YOUR_CREDENTIAL_ID",
            "name": "Migma API"
          }
        }
      }
    ],
    "connections": {
      "Read Stores": {
        "main": [[{ "node": "Loop Stores", "type": "main", "index": 0 }]]
      },
      "Loop Stores": {
        "main": [[{ "node": "Import Store", "type": "main", "index": 0 }]]
      },
      "Import Store": {
        "main": [[{ "node": "Wait", "type": "main", "index": 0 }]]
      },
      "Wait": {
        "main": [[{ "node": "Check Status", "type": "main", "index": 0 }]]
      },
      "Check Status": {
        "main": [[{ "node": "Is Ready?", "type": "main", "index": 0 }]]
      },
      "Is Ready?": {
        "main": [
          [{ "node": "Connect Shopify", "type": "main", "index": 0 }],
          [{ "node": "Wait", "type": "main", "index": 0 }]
        ]
      },
      "Connect Shopify": {
        "main": [[{ "node": "Generate Email", "type": "main", "index": 0 }]]
      },
      "Generate Email": {
        "main": [[{ "node": "Wait", "type": "main", "index": 0 }]]
      },
      "Check Generation": {
        "main": [[{ "node": "Is Ready?", "type": "main", "index": 0 }]]
      },
      "Is Ready?": {
        "main": [
          [{ "node": "Send Test Email", "type": "main", "index": 0 }],
          [{ "node": "Wait", "type": "main", "index": 0 }]
        ]
      },
      "Send Test Email": {
        "main": [[{ "node": "Loop Stores", "type": "main", "index": 0 }]]
      }
    }
  }
  ```
</Accordion>

<Info>
  **Note:** To send test emails, make sure your API key has the `EMAIL_SEND` permission enabled in Migma Settings → Developers → API Keys.
</Info>

### Using Webhooks Instead of Polling

For better performance, use [Migma webhooks](/webhooks) instead of wait/check loops:

1. Add a **Webhook** node in n8n and copy the webhook URL
2. In Migma Settings → Developers → Webhooks, create a webhook
3. Subscribe to events: `project.import.completed` and `email.generation.completed`
4. Your n8n workflow will be triggered automatically when events occur

## Tips

<AccordionGroup>
  <Accordion title="Passing Data Between Nodes" icon="arrow-right">
    Use n8n expressions to reference previous node data:

    * `{{ $json.data.projectId }}` - Access projectId from current node
    * `{{ $('Import Brand').item.json.data.projectId }}` - Access data from specific node
  </Accordion>

  <Accordion title="Handling Errors" icon="triangle-exclamation">
    Add an **Error Trigger** node to catch failures and send alerts or retry logic.
  </Accordion>

  <Accordion title="Batch Processing" icon="layer-group">
    Use **Split in Batches** node to process multiple items from spreadsheets or databases.
  </Accordion>

  <Accordion title="Export Formats" icon="file-export">
    Available export endpoints:

    * `/v1/export/html/{conversationId}` - Standard HTML
    * `/v1/export/klaviyo/{conversationId}` - Klaviyo format
    * `/v1/export/mailchimp/{conversationId}` - Mailchimp format
    * `/v1/export/mjml/{conversationId}` - MJML format
  </Accordion>
</AccordionGroup>

## Need Help?

<CardGroup cols={2}>
  <Card title="API Documentation" icon="book" href="/api-reference/introduction">
    Complete API reference with all endpoints
  </Card>

  <Card title="Webhooks" icon="bolt" href="/webhooks">
    Set up real-time event notifications
  </Card>

  <Card title="n8n Documentation" icon="book" href="https://docs.n8n.io">
    Learn more about n8n
  </Card>

  <Card title="Join Discord" icon="discord" href="https://discord.gg/ZB6c2meCUA">
    Get help from the community
  </Card>
</CardGroup>
