Skip to main content

POST /api/lead

Store lead email addresses submitted through the landing page. This endpoint is triggered by the ButtonLead component.

Request

email
string
required
Email address of the lead. Must be a valid email format.

Response

success
object
Empty object returned on successful lead storage.
error
string
Error message returned when request fails.

Code Examples

curl -X POST https://8space.app/api/lead \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]"
  }'

Request Validation

The endpoint validates the following:
  • Email presence: The email field must be provided in the request body
  • Email format: Must be a valid email address format
packages/landing/app/api/lead/route.ts
export async function POST(req: NextRequest) {
  const body = await req.json();

  if (!body.email) {
    return NextResponse.json({ error: "Email is required" }, { status: 400 });
  }

  try {
    // TODO: Add your own lead storage logic here
    // For instance, save to Supabase or send a welcome email
    return NextResponse.json({});
  } catch (e: any) {
    console.error(e);
    return NextResponse.json({ error: e.message }, { status: 500 });
  }
}

Error Handling

400
error
Validation ErrorReturned when:
  • Email field is missing from request body
{
  "error": "Email is required"
}
500
error
Internal Server ErrorReturned when:
  • Database operation fails
  • Unexpected server error occurs
{
  "error": "Error message details"
}

Success Response

Status Code: 200 OK
{}

Implementation Notes

  • The current implementation includes a TODO for adding custom lead storage logic
  • Consider integrating with Supabase for lead storage or sending welcome emails
  • All errors are logged to the console for debugging

Build docs developers (and LLMs) love