Intermediate Use Case
Adding Contacts, Tags, & Sending Trigger-Based Email Sequences with Zapier and Lemón API.
💡 How It Works:
- A contact list named "User List" is automatically created.
- A pre-built 7-day email sequence that has led to sales in the past 90 days (tested and proven to convert leads into customers).
- The 7-day email sequence is triggered by the "new_user" tag.
- To modify the email sequence, you only need to go to Email Funnels and tweak the placeholders like [Your Name],[Customer Pain Point], etc.
📌 Getting Started:
Key Features
- Add a contact to a contact list, tag/untag contacts dynamically
- Send transactional emails
- Triggers and actions
Example Use Case with Zapier:
👉Google Form + Lemón
Example Use Case with Lemón API:
Authorization
Include your API key in the X-Auth-APIKey header. Retrieve your API key from the Integrate > API & SMTP section in the Lemón UI.
Sample HTTP Request (for email sending):
POST /transactional/send
Host: app.xn--lemn-sqa.com
Content-Type: application/json
X-Auth-APIKey: your_lemon_api_key
{
"fromname": "Your SaaS",
"fromemail": "noreply@yoursaas.com",
"to": "recipient@example.com",
"subject": "Welcome!",
"body": "Thank you for joining us."
}
Sample HTTP Request (for adding a contact):
Include your list ID in the {your_list_id} header. Retrieve your list ID from Contacts > Contact Lists > User List.
POST /lists/{your_list_id}/feed
Host: app.xn--lemn-sqa.com
Content-Type: application/json
X-Auth-APIKey: your_lemon_api_key
{
"email": "ted@domain.com",
"tags": [
"new_user"
],
"removetags": [
"string"
],
"resubscribe": false,
"unsubscribe": false,
"data": {
"First Name": "Ted"
}
}
For more details about available routes, refer to the API documentation at Lemón API Docs.
Example Use Case: AI Agent Sending A Welcome Email
👉Click here to demo the AI Agent.
When you sign up, your name and email are automatically added to the default contact list and tagged as a 'new_user,' and you will receive a welcome email.
This is to demonstrate how you can add a user to a contact list, tag them, send an email, and trigger the 7-day email sequence.
If you interact with it, you will also get the contextual email example from the 'Advanced Use Case' after the 'end_conversation' event fires.
More Use Case:
👉Custom Form + Lemón
In this case, when a new user signs up - they get added to the default "User List" contact list and tag them as "new_user".
This will trigger the pre-built 7-day email sequence designed to convert new users into paying customers.
Here are the scripts used in Javascript & Python:
Javascript
'use server'
import { contactFormSchema } from '@/lib/schema'
import { z } from 'zod'
export async function contactFormAction(
_prevState: unknown,
formData: FormData
) {
const defaultValues = z
.record(z.string(), z.string())
.parse(Object.fromEntries(formData.entries()))
try {
const data = contactFormSchema.parse(Object.fromEntries(formData))
// Make the API call to Lemón to add a contact to the "User List"
const addContactResponse = await fetch(`https://app.xn--lemn-sqa.com/api/lists/${process.env.LEMN_LIST_ID}/feed`, {
method: 'POST',
headers: {
'accept': 'application/json',
'X-Auth-APIKey': process.env.LEMON_EMAIL_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: data.email,
tags: ['new_user'],
resubscribe: false,
unsubscribe: false,
data: {
'First Name': data.name
}
})
})
if (!addContactResponse.ok) {
throw new Error('Failed to add contact to mailing list')
}
// Send transactional email via Lemón API
const sendEmailResponse = await fetch('https://app.xn--lemn-sqa.com/api/transactional/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Auth-APIKey': process.env.LEMN_API_KEY
},
body: JSON.stringify({
fromname: "Alexa",
fromemail: "mail@elitegci.com",
to: data.email,
subject: "Welcome",
body: "<html><body>Welcome to my service</body></html>"
})
})
if (!sendEmailResponse.ok) {
throw new Error('Failed to send welcome email')
}
return {
defaultValues: {
name: '',
email: '',
message: '',
},
success: true,
errors: null,
}
} catch (error) {
console.error('Error in contactFormAction:', error)
if (error instanceof z.ZodError) {
return {
defaultValues,
success: false,
errors: Object.fromEntries(
Object.entries(error.flatten().fieldErrors).map(([key, value]) => [
key,
value?.join(', '),
])
),
}
}
return {
defaultValues,
success: false,
errors: {
form: 'An error occurred while processing your request. Please try again.'
},
}
}
}
Python
import os
import requests
from typing import Dict, Any
from dataclasses import dataclass
@dataclass
class ContactFormData:
name: str
email: str
message: str
def validate_form_data(data: Dict[str, Any]) -> ContactFormData:
# Basic validation (you might want to use a library like Pydantic for more robust validation)
if not data.get('name') or len(data['name']) < 2 or len(data['name']) > 32:
raise ValueError("Name must be between 2 and 32 characters")
if not data.get('email') or '@' not in data['email']:
raise ValueError("Invalid email address")
if not data.get('message') or len(data['message']) < 2 or len(data['message']) > 1000:
raise ValueError("Message must be between 2 and 1000 characters")
return ContactFormData(
name=data['name'],
email=data['email'],
message=data['message']
)
def contact_form_action(form_data: Dict[str, Any]) -> Dict[str, Any]:
try:
data = validate_form_data(form_data)
# Add contact to Lemón list
add_contact_response = requests.post(
f"https://app.xn--lemn-sqa.com/api/lists/{os.environ['LEMN_LIST_ID']}/feed",
headers={
'accept': 'application/json',
'X-Auth-APIKey': os.environ['LEMN_API_KEY'],
'Content-Type': 'application/json'
},
json={
'email': data.email,
'tags': ['new_user'],
'resubscribe': False,
'unsubscribe': False,
'data': {
'First Name': data.name
}
}
)
if not add_contact_response.ok:
raise Exception('Failed to add contact to mailing list')
# Send transactional email
send_email_response = requests.post(
'https://app.xn--lemn-sqa.com/api/transactional/send',
headers={
'Content-Type': 'application/json',
'X-Auth-APIKey': os.environ['LEMN_API_KEY']
},
json={
'fromname': "Alexa",
'fromemail': "mail@elitegci.com",
'to': data.email,
'subject': "Welcome",
'body': "<html><body>Welcome to my service</body></html>"
}
)
if not send_email_response.ok:
raise Exception('Failed to send welcome email')
return {
'defaultValues': {
'name': '',
'email': '',
'message': '',
},
'success': True,
'errors': None,
}
except ValueError as ve:
return {
'defaultValues': form_data,
'success': False,
'errors': str(ve),
}
except Exception as e:
print(f"Error in contact_form_action: {str(e)}")
return {
'defaultValues': form_data,
'success': False,
'errors': {
'form': 'An error occurred while processing your request. Please try again.'
},
}
# Example usage
if __name__ == "__main__":
sample_form_data = {
"name": "John Doe",
"email": "john@example.com",
"message": "Hello, this is a test message."
}
result = contact_form_action(sample_form_data)
print(result)
Note: These email sequences are plug-and-play, saving you time while optimizing your email workflows.