DOCS · N8N WORKFLOW

Superprompt: Build n8n Workflow

UPDATED 22 NOVEMBER 2025

Use with: Claude Code, Cursor

TASK: Create n8n workflow JSON for automated win-back campaigns

CONTEXT:
I want to automate win-back campaigns for at-risk customers using n8n and the AIVA API.

WORKFLOW LOGIC:

- **Trigger:** Schedule (every Monday at 9 AM)

- **Get At-Risk Customers:** Call AIVA API

- **Filter:** Only if count >= 10

- **Loop Through Customers:** For each customer:

   - Generate personalized win-back email content using OpenAI
   - Send email via SendGrid
   - Log to Google Sheets

- **Send Summary:** Slack notification with campaign results

API DETAILS:

- Endpoint: GET https://api.getaiva.ai/api/merchant/{merchantId}/customers?segment=At%20Risk

- Auth: X-API-Key header from environment variable

- Response: { customers: [...], total: 87 }

CUSTOMER DATA STRUCTURE:
{
  "email": "john@example.com",
  "firstName": "John",
  "lastName": "Smith",
  "totalSpent": 1245.50,
  "daysSinceLastOrder": 45,
  "ordersCount": 8
}

EMAIL PERSONALIZATION:

- Use customer first name

- Reference their total spend

- Offer 20% discount code (generate unique per customer)

- Urgency: "This week only"

- Include top 3 products they previously bought (if available)

REQUIRED N8N NODES:

- Schedule Trigger

- HTTP Request (AIVA API)

- If (check count >= 10)

- Loop Over Items

- OpenAI (GPT-4 for email content)

- SendGrid (email delivery)

- Google Sheets (logging)

- Slack (summary notification)

ENVIRONMENT VARIABLES NEEDED:

- AIVA_API_KEY

- AIVA_MERCHANT_ID

- OPENAI_API_KEY

- SENDGRID_API_KEY

- GOOGLE_SHEETS_ID

- SLACK_WEBHOOK_URL

DELIVERABLES:

- Complete n8n workflow JSON file

- README with setup instructions

- Environment variable template

- Email template suggestions

CREATE THE WORKFLOW JSON NOW.
Include all nodes, connections, and configuration.
Make it copy-paste ready for import into n8n.
`"

**Expected Result:** A complete n8n workflow JSON ready to import. - 
Building something with the AIVA API or MCP server? We read every developer message.
Talk to us