Fix Resend contact sync payload and support separate contacts key

This commit is contained in:
nmemmert
2026-04-09 16:05:46 -04:00
parent 3a9d11cf40
commit afb80aaf2a
2 changed files with 6 additions and 10 deletions
+3
View File
@@ -7,6 +7,9 @@
# 3. Paste it below # 3. Paste it below
RESEND_API_KEY=re_your_api_key_here RESEND_API_KEY=re_your_api_key_here
# Optional: use a separate key for Contacts/Segments if your main key is send-only
RESEND_CONTACTS_API_KEY=
# Email address that receives contact form submissions # Email address that receives contact form submissions
RESEND_TO=vbvwithnate@outlook.com RESEND_TO=vbvwithnate@outlook.com
+3 -10
View File
@@ -122,9 +122,10 @@ app.post('/api/contact', contactRateLimit, async (req, res) => {
const resend = new Resend(process.env.RESEND_API_KEY) const resend = new Resend(process.env.RESEND_API_KEY)
const { firstName, lastName } = splitName(trimmedName) const { firstName, lastName } = splitName(trimmedName)
const contactResend = new Resend(process.env.RESEND_CONTACTS_API_KEY ?? process.env.RESEND_API_KEY)
try { try {
const { error: contactError } = await resend.contacts.create({ const { error: contactError } = await contactResend.contacts.create({
email: trimmedEmail, email: trimmedEmail,
firstName, firstName,
lastName, lastName,
@@ -132,22 +133,14 @@ app.post('/api/contact', contactRateLimit, async (req, res) => {
...(process.env.RESEND_SEGMENT_ID ...(process.env.RESEND_SEGMENT_ID
? { segments: [{ id: process.env.RESEND_SEGMENT_ID }] } ? { segments: [{ id: process.env.RESEND_SEGMENT_ID }] }
: {}), : {}),
properties: {
source: 'website-contact-form',
last_message_at: new Date().toISOString(),
},
}) })
if (contactError) { if (contactError) {
const { error: updateError } = await resend.contacts.update({ const { error: updateError } = await contactResend.contacts.update({
email: trimmedEmail, email: trimmedEmail,
firstName, firstName,
lastName, lastName,
unsubscribed: false, unsubscribed: false,
properties: {
source: 'website-contact-form',
last_message_at: new Date().toISOString(),
},
}) })
if (updateError) { if (updateError) {