# Led Sign 24 Storefront API — API Reference

API for building storefronts and ecommerce experiences.

## Quick Start

1. **Authenticate** — `POST /api/auth/sign-in/email` with `{ email, password }` to get a session cookie, or browse as a guest
2. **Browse products** — `GET /api/products` to list products, `GET /api/products/{id}` for details
3. **Search** — `GET /api/search?q=keyword` for full-text search
4. **Add to cart** — Use the cart endpoints to manage items
5. **Apply discount** — `POST /api/cart/apply-discount` with a discount code
6. **Checkout** — `POST /api/payment-amount` to calculate the final total, then complete payment via Stripe
7. **View orders** — `GET /api/orders` to see order history

## Authentication

Two authentication methods are supported:

**Session Cookie** — Sign in via `POST /api/auth/sign-in/email` with `{ email, password }`. The `better-auth.session_token` cookie is set automatically.

**API Key** — Pass an `x-api-key` header with a scoped API key. Create keys at `/account/developer` or via `POST /api/auth/api-key/create`. Keys are scoped to specific resources (products, cart, orders, reviews, wishlist).

## Error Format

All errors return `{ error: string }`. Validation errors additionally include `{ details: { fieldErrors, formErrors } }` with per-field messages.

## Table of Contents

- [Contact](#contact) — Contact form submissions.

## Contact
> Contact form submissions.

### POST `/api/contact`

**Submit contact form** ` PUBLIC `

Accepts a contact form submission, stores it in the Payload CMS `contact-form-submissions` collection and emails a notification to the Led Sign 24 inbox (reply-to is the sender). No authentication is required. Rate limited to 5 submissions per minute per client.

> **Dashboard:** Payload Admin > Contact Form Submissions

#### Request Body

| Field | Type | Required | Constraints | Description |
|-------|------|----------|-------------|-------------|
| `name` | string | Yes | minLength: 1, maxLength: 150, pattern | Full name of the person submitting the form |
| `email` | string | Yes | minLength: 5, maxLength: 320, format: email | Contact email address |
| `subject` | string | Yes | minLength: 1, maxLength: 200 | Subject line for the contact message |
| `message` | string | Yes | minLength: 1, maxLength: 5000 | Body of the contact message |

#### Responses

| Status | Description |
|--------|-------------|
| 201 | Contact form submitted successfully |
| 400 | Validation error — missing or invalid fields |
| 429 | Too many contact submissions from this client |
| 500 | Internal server error |

**cURL Example:**
```bash
curl -X POST "https://ledsign24dk.vercel.app/api/contact"
```

---

## Error Reference

All errors return a JSON object with an `error` field:
```json
{ "error": "Human-readable error message" }
```

Validation errors (400) additionally include structured details:
```json
{
  "error": "Validation failed",
  "details": {
    "fieldErrors": { "email": ["Invalid email address"] },
    "formErrors": []
  }
}
```
