Webhook handler for new library submissions. Validates the JSON body with zod, then emails the owner when a request comes through authorized.
POST — sends the notification email. Any other method returns 405.
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
{ "library": "Main St. Library", "firstName": "Ada", "lastName": "Lovelace", "email": "ada@example.com", "country": "US", "state": "CA", "story": "A story about a library…", "bg": true }
| Field | Type | Notes |
|---|---|---|
library | string | required |
firstName | string | required |
lastName | string | required |
email | string | required, must be a valid email |
country | string | required |
state | string | optional |
story | string | required |
bg | boolean | required |
200 {"ok":true} — valid + authorized, email sent401 {"error":"Unauthorized"} — missing/wrong secret400 {"error":"Validation failed", ...} — body failed zod validation405 {"error":"Method not allowed"} — not a POSTSent 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).