Skip to main content

Overview

The /api/confirmar endpoint handles RSVP confirmations for wedding guests. It accepts guest information via POST request and sends an email notification with the RSVP details using Nodemailer.

Endpoint

POST /api/confirmar

Request Parameters

nombre
string
required
The name of the guest confirming attendance. This field is required.
asistencia
string
required
Attendance confirmation status. This field is required.
alergia
string
Any food allergies or dietary restrictions. This field is optional.

Response

Success Response

ok
boolean
Indicates the RSVP was successfully processed and email was sent.
Status Code: 200 OK
{
  "ok": true
}

Error Responses

Missing Required Fields

error
string
Error message describing the issue.
Status Code: 400 Bad Request
{
  "error": "Faltan campos obligatorios"
}

Server Error

Status Code: 500 Internal Server Error
{
  "error": "Error message details"
}

Examples

cURL

curl -X POST https://yourdomain.com/api/confirmar \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "Juan García",
    "asistencia": "Confirmo asistencia",
    "alergia": "Ninguna"
  }'

JavaScript/TypeScript

const response = await fetch('/api/confirmar', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    nombre: 'Juan García',
    asistencia: 'Confirmo asistencia',
    alergia: 'Ninguna'
  })
});

const data = await response.json();

if (response.ok) {
  console.log('RSVP confirmed successfully:', data.ok);
} else {
  console.error('Error:', data.error);
}

Fetch with Error Handling

try {
  const response = await fetch('/api/confirmar', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      nombre: 'María López',
      asistencia: 'No podré asistir',
      alergia: 'Intolerancia al gluten'
    })
  });

  const data = await response.json();

  if (!response.ok) {
    throw new Error(data.error || 'Failed to submit RSVP');
  }

  return data;
} catch (error) {
  console.error('RSVP submission failed:', error);
  throw error;
}

Environment Variables

The endpoint requires the following environment variables to be configured:

SMTP Configuration

The endpoint is configured to use IONOS SMTP service with the following settings:
  • Host: smtp.ionos.es
  • Port: 587
  • Secure: false (uses STARTTLS)

Email Notification

When an RSVP is successfully submitted, an email is sent with the following details:
  • From: “Web Boda” <EMAIL_USER>
  • To: EMAIL_TO
  • Subject: “✉️ Confirmación de asistencia – [Guest Name]”
  • Content: HTML formatted message with guest name, allergies, and attendance status

Error Handling

The endpoint implements comprehensive error handling:
  1. Validation Errors (400): Returns when required fields (nombre or asistencia) are missing
  2. Server Errors (500): Returns when email sending fails or other unexpected errors occur
  3. All errors are logged to the console for debugging purposes

Implementation Notes

  • The endpoint uses prerender = false to ensure it runs on the server
  • Built on Astro’s APIRoute type
  • Uses Nodemailer for reliable email delivery
  • All responses include proper Content-Type: application/json headers

Build docs developers (and LLMs) love