New Library Email

Webhook handler for new library submissions. Validates the JSON body with zod, then emails the owner when a request comes through authorized.

Endpoint

POST — sends the notification email. Any other method returns 405.

Authorization

The request must include a header matching the val's secret (either use the existing CLOUDFLARE_API_KEY env var value, or replace it with your own key):

X-Webhook-Secret: <your secret>

Without a matching header, the endpoint returns 401. You can add your own secret here:

👉 Add WEBHOOK_SECRET here: https://www.val.town/x/the_card_catalog/new-library-email/environment-variables?key=WEBHOOK_SECRET

Request body

{ "library": "Main St. Library", "firstName": "Ada", "lastName": "Lovelace", "email": "ada@example.com", "country": "US", "state": "CA", "story": "A story about a library…", "bg": true }
FieldTypeNotes
librarystringrequired
firstNamestringrequired
lastNamestringrequired
emailstringrequired, must be a valid email
countrystringrequired
statestringoptional
storystringrequired
bgbooleanrequired

Responses

  • 200 {"ok":true} — valid + authorized, email sent
  • 401 {"error":"Unauthorized"} — missing/wrong secret
  • 400 {"error":"Validation failed", ...} — body failed zod validation
  • 405 {"error":"Method not allowed"} — not a POST

Email

Sent via std/email to the val owner's address by default. To send to a different address, set a to in the call (or add a NOTIFY_EMAIL env var).