apps/docs/src/app/api/newsletter/README.md
This API endpoint handles newsletter subscriptions via Brevo (formerly Sendinblue) with double opt-in.
15)36)Add this variable to your Vercel project or .env.local file:
BREVO_API_KEY=your_api_key_here
In your Vercel project settings:
BREVO_API_KEYThe newsletter form is available through the FooterNewsletterForm component:
import { FooterNewsletterForm } from "@prisma-docs/ui/components/newsletter";
export default function Page() {
return <FooterNewsletterForm blog={false} />;
}
POST /api/newsletter
{
"email": "[email protected]"
}
Success (200)
{
"message": "Please check your email to confirm subscription"
}
Already Subscribed (200)
{
"message": "Already subscribed",
"alreadySubscribed": true
}
Error (400)
{
"error": "Invalid email address"
}
Error (500)
{
"error": "Newsletter service is not configured"
}
This implementation uses Brevo's double opt-in feature:
This ensures compliance with GDPR and other privacy regulations.
Check that the BREVO_API_KEY environment variable is set correctly.
Check the server logs for detailed error messages from Brevo. Common issues:
15)36)In development mode (NODE_ENV=development), the API will return additional debug information in the error response:
{
"error": "Failed to subscribe. Please try again later.",
"debug": {
"status": 400,
"brevoError": {
"code": "invalid_parameter",
"message": "..."
}
}
}
Check the browser console for "API Error Debug:" logs.
Create a .env.local file in the app root:
BREVO_API_KEY=your_api_key_here
Restart your development server after adding environment variables.
To customize the list ID or template ID, edit the API route:
// In route.ts, around line 60-61
includeListIds: [15], // Change to your list ID
templateId: 36, // Change to your template ID
The API is configured to allow requests from:
To add more origins, update the corsHeaders in route.ts.