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
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
+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 { 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) {