DEV Community

Pirate Prentice
Pirate Prentice

Posted on

n8n Klaviyo Node: Sync Contacts, Trigger Campaigns, and Automate Email Flows [Free Workflow JSON]

n8n Klaviyo Node: Sync Contacts, Trigger Campaigns, and Automate Email Flows [Free Workflow JSON]

Klaviyo powers email marketing for e-commerce: segmentation, dynamic campaigns, predictive analytics, and SMS. The n8n Klaviyo node lets you sync customer lists, add tags, trigger email sequences, and track campaign performance without leaving your n8n workflow. This guide covers every operation, the gotchas, and three production-ready workflow patterns.


What the Klaviyo Node Does

The n8n Klaviyo node exposes four core resources:

Resource Operations
Contact Create, Get, Get All, Delete, Upsert (create or update)
Metric Get All (events), Track Event (custom events)
List Create, Get, Get All, Delete, Add Profiles, Remove Profiles, Get All Profiles
Campaign Get All, Get, Update, Send, Clone, Cancel

Authentication uses a Klaviyo API Key (Settings → Account → API Keys). Keys can be private (full access) or public (restricted read-only).


Setting Up the Credential

  1. Log into Klaviyo → Settings (bottom-left) → Account
  2. Click API Keys
  3. Click Create API Key — Klaviyo generates a private key (36+ chars, starts pk_ for private keys)
  4. In n8n, add a Klaviyo credential:
    • Paste the private API key
    • Leave the API version as default (v1 or v2 depending on n8n version)
  5. Test connection and save

Important: Private API keys have full read/write access. Rotate keys annually. Never share private keys in logs or commits. Use environment variables or n8n credentials vault.


Core Operations

Contact Resource

Create — adds a new contact (subscriber) to Klaviyo. Required: email address or phone number. Optional: first name, last name, company, custom fields, tags, list assignment.

Upsert — creates a new contact or updates existing one (identified by email/phone). Avoids duplicate subscriber errors. Most common operation for list sync workflows.

Get All — retrieves all contacts in your Klaviyo account with optional filters (email, tag, list, status).

Update — modifies an existing contact. Can change name, custom fields, tags, subscribed status.

Delete — removes a contact from Klaviyo entirely (GDPR compliance).

Gotcha #1: Contacts in Klaviyo are global (not scoped to lists). Adding a contact to a list tags it with the list. Deleting a contact removes it from all lists.

List Resource

Get All — retrieves all lists (segments) in your Klaviyo account. Each list is a static audience.

Create — builds a new list (e.g., "VIP customers," "abandoned cart," "trial signups").

Add Profiles — adds one or more contacts to a list (identified by contact ID or email).

Remove Profiles — removes contacts from a list.

Get All Profiles — lists all members of a specific list.

Gotcha #2: Lists are static. For dynamic audiences, use Klaviyo's "Segments" feature (not via API yet, but you can automate tag-based assignment and filter on tags).

Campaign Resource

Get All — retrieves all campaigns (past, scheduled, draft).

Get — retrieves a single campaign with performance metrics (sends, opens, clicks, revenue).

Update — modifies campaign settings (name, subject, from email, content, scheduling).

Send — immediately sends a campaign to a list. Irreversible.

Clone — duplicates an existing campaign as a draft (useful for templating).

Cancel — cancels a scheduled campaign.

Gotcha #3: Once sent, a campaign cannot be edited. Clone it first, edit the clone, then send the new version.

Metric Resource

Track Event — logs a custom event for a contact (e.g., "viewed product," "made purchase," "abandoned cart"). Events trigger automation sequences and segmentation rules.

Get All — lists all custom metrics (event types) defined in your Klaviyo account.

Gotcha #4: Custom events must be pre-registered in Klaviyo. If you try to track an event that doesn't exist, Klaviyo silently ignores it. Create the metric in Klaviyo UI first OR define it via n8n Metric → Create (if available in your n8n version).


Three Production Workflow Patterns

Pattern 1: Sync E-commerce Customers to Klaviyo (Daily)

Trigger: Schedule (daily, 2 AM)

Flow:

  1. HTTP Request → pull new customers from your database (SQL, Shopify API, Stripe API)
  2. Loop over each customer
  3. Klaviyo Upsert → Create or update contact with email, name, purchase count, lifetime value
  4. Klaviyo List → Add Profiles to a "Registered Customers" list
  5. Slack notification → log how many synced

Why: Keeps Klaviyo in sync with your authoritative customer database. Avoids manual imports.


Pattern 2: Trigger Email Sequence on Purchase

Trigger: Webhook (Shopify order created, or Stripe charge succeeded)

Flow:

  1. Parse webhook → extract customer email, order total, product name
  2. Klaviyo Upsert → update contact with last_purchase_date and ltv custom fields
  3. Klaviyo Metric → Track Event "Purchased" with order total as value
  4. Klaviyo Campaign → Get all campaigns, find the one tagged "post-purchase" (or use automation workflows instead — see gotcha below)

Why: Fires Klaviyo automation sequences (e-books, follow-ups, reviews) triggered by purchase events. No manual campaign triggering.

Gotcha: Use Klaviyo's native Automation Workflows (email sequences triggered by events) rather than n8n triggering campaigns. n8n's campaign send is manual/broadcast; automations are event-based and more flexible.


Pattern 3: Tag Contacts Dynamically Based on Engagement

Trigger: Schedule (daily)

Flow:

  1. HTTP Request → fetch contacts with engagement metrics (open rate > 30%, click > 2x)
  2. Loop over each contact
  3. Klaviyo Contact → Update with tag "High Engager"
  4. Conditional node → if engagement drops, remove tag "High Engager," add tag "At Risk"
  5. Log → count updated

Why: Keeps Klaviyo tags fresh without manual work. Enables dynamic email segmentation and re-engagement campaigns.


Common Gotchas & Solutions

Gotcha #1: API Rate Limits

Issue: Klaviyo rate-limits at 10 req/sec per API key. Bulk updates fail.

Solution: Use Klaviyo's Batch operations (if n8n supports) or add a 100ms delay between Contact operations using n8n's Wait node.

Gotcha #2: Contact Merge (Deduplication)

Issue: Upsert by email prevents duplicates, but if you upsert by different identifiers (phone, custom ID), you can create multiple records for one person.

Solution: Always upsert by primary identifier (email). Use tags/custom fields to track alternate IDs.

Gotcha #3: Unsubscribe Compliance

Issue: Manually adding contacts to Klaviyo violates CAN-SPAM if they didn't opt in.

Solution: Never bulk-import cold lists. Only add contacts who have explicitly subscribed (checkout form, lead magnet, etc.). Check Klavioy's unsubscribe list before adding.


Workflow JSON (Copy & Paste)

\json
{
"name": "Sync Shopify Orders to Klaviyo",
"nodes": [
{
"parameters": {
"httpMethod": "GET",
"url": "https://your-shopify-store.myshopify.com/admin/api/2024-01/orders.json?limit=50&status=any",
"authentication": "genericCredentialType",
"genericCredentialType": "shopifyApi",
"sendBody": false
},
"name": "Fetch Shopify Orders",
"type": "n8n-nodes-base.httpRequest",
"position": [250, 300],
"typeVersion": 4.4
},
{
"parameters": {
"resource": "contact",
"operation": "upsert",
"email": "={{$json.email}}",
"firstName": "={{$json.billing_address.first_name}}",
"lastName": "={{$json.billing_address.last_name}}",
"customProperties": "={
\"ltv\": {{$json.total_price}}
}"
},
"name": "Upsert to Klaviyo",
"type": "n8n-nodes-base.klaviyo",
"position": [500, 300],
"typeVersion": 1.0
},
{
"parameters": {
"resource": "list",
"operation": "addProfiles",
"listId": "ABC123DEF456",
"profileIds": "={{$json.contact_id}}"
},
"name": "Add to List",
"type": "n8n-nodes-base.klaviyo",
"position": [750, 300],
"typeVersion": 1.0
}
],
"connections": {
"Fetch Shopify Orders": {
"main": [
[
{
"node": "Upsert to Klaviyo",
"type": "main",
"index": 0
}
]
]
},
"Upsert to Klaviyo": {
"main": [
[
{
"node": "Add to List",
"type": "main",
"index": 0
}
]
]
}
}
}
\
\


Key Takeaways

  1. Upsert is your friend — use it for list syncs; avoids duplicates.
  2. Track events, not campaigns — let Klaviyo's automation sequences handle the sends.
  3. Respect opt-in — only add contacts who explicitly consented.
  4. Tag for segmentation — tags are powerful; use them to organize contacts and trigger dynamic campaigns.
  5. Monitor rate limits — add delays for bulk operations (50+ contacts) to stay under 10 req/sec.

Related Articles

Learn n8n workflows that actually drive revenue. Explore 18+ workflow templates →

Ready to automate your SMB? Our done-for-you n8n audit identifies 3 high-ROI workflows for your business in 30 min. Book your audit →

Top comments (0)