From afb80aaf2acb30833192999b632eefb95ba3ae24 Mon Sep 17 00:00:00 2001 From: nmemmert Date: Thu, 9 Apr 2026 16:05:46 -0400 Subject: [PATCH] Fix Resend contact sync payload and support separate contacts key --- .env.example | 3 +++ server.js | 13 +++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index e6e9553..e0940c5 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,9 @@ # 3. Paste it below 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 RESEND_TO=vbvwithnate@outlook.com diff --git a/server.js b/server.js index ee7e2b1..f0c3737 100644 --- a/server.js +++ b/server.js @@ -122,9 +122,10 @@ app.post('/api/contact', contactRateLimit, async (req, res) => { const resend = new Resend(process.env.RESEND_API_KEY) const { firstName, lastName } = splitName(trimmedName) + const contactResend = new Resend(process.env.RESEND_CONTACTS_API_KEY ?? process.env.RESEND_API_KEY) try { - const { error: contactError } = await resend.contacts.create({ + const { error: contactError } = await contactResend.contacts.create({ email: trimmedEmail, firstName, lastName, @@ -132,22 +133,14 @@ app.post('/api/contact', contactRateLimit, async (req, res) => { ...(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) { - const { error: updateError } = await resend.contacts.update({ + const { error: updateError } = await contactResend.contacts.update({ email: trimmedEmail, firstName, lastName, unsubscribed: false, - properties: { - source: 'website-contact-form', - last_message_at: new Date().toISOString(), - }, }) if (updateError) {