# curl

## What this is

Command-line requests against the intake endpoint: form-encoded, form-encoded with redirect, JSON, multipart, an idempotency key, and a honeypot negative test. Useful to confirm a form id works before touching a site, and as the reference for any HTTP client.

Files: [`examples.sh`](examples.sh).

This sample uses the placeholder form id `au_xxxxxxx`. Replace it (or export `CONTACTUSIQ_FORM_ID`). There is no Turnstile from the command line; leave `cf-turnstile-response` out and the form runs at stricter heuristics, or configure the form to not require Turnstile while testing.

## Prerequisites

- `curl` 7.x or newer.
- A published form and a verified domain. Requests must carry an `Origin` (or `Referer`) header matching a verified domain, or they return `200` and are silently dropped.

## Steps

1. `export CONTACTUSIQ_FORM_ID=au_xxxxxxx` and `export CONTACTUSIQ_ORIGIN=https://www.example.com` (a verified domain).
2. Run `./examples.sh`, or copy individual commands from below.

## The code

Form-encoded (the browser default for `<form method="POST">`):

```sh
curl -i https://api.contactusiq.com/s/au_xxxxxxx \
  -H "Origin: https://www.example.com" \
  --data-urlencode "name=Test Person" \
  --data-urlencode "email=test@example.com" \
  --data-urlencode "message=Hello" \
  --data-urlencode "_honeypot="
```

With a redirect (`303` + `Location`):

```sh
curl -i https://api.contactusiq.com/s/au_xxxxxxx \
  -H "Origin: https://www.example.com" \
  --data-urlencode "name=Test Person" --data-urlencode "email=test@example.com" \
  --data-urlencode "message=Hello" --data-urlencode "_honeypot=" \
  --data-urlencode "_redirect=https://www.example.com/thanks.html"
```

JSON (`200` + `{"ok":true,"id":"sub_..."}`):

```sh
curl -i https://api.contactusiq.com/s/au_xxxxxxx \
  -H "Origin: https://www.example.com" \
  -H "Content-Type: application/json" -H "Accept: application/json" \
  --data '{"name":"Test Person","email":"test@example.com","message":"Hello","_honeypot":""}'
```

Multipart:

```sh
curl -i https://api.contactusiq.com/s/au_xxxxxxx \
  -H "Origin: https://www.example.com" -H "Accept: application/json" \
  -F "name=Test Person" -F "email=test@example.com" -F "message=Hello" -F "_honeypot="
```

Idempotency key (a repeat within 10 minutes returns the same id and creates nothing; `_idempotency` as a field works the same):

```sh
curl https://api.contactusiq.com/s/au_xxxxxxx \
  -H "Origin: https://www.example.com" \
  -H "Content-Type: application/json" -H "Accept: application/json" \
  -H "Idempotency-Key: order-1234-contact" \
  --data '{"name":"Test Person","email":"test@example.com","message":"Hello","_honeypot":""}'
```

Schema of the form (field list and validation rules, no auth):

```sh
curl https://api.contactusiq.com/f/au_xxxxxxx/schema
```

## How to test

- Form-encoded: `HTTP/2 200` and an HTML body.
- With `_redirect`: `HTTP/2 303` and `location: https://www.example.com/thanks.html`.
- JSON or multipart with `Accept: application/json`: `HTTP/2 200` and `{"ok":true,"id":"sub_..."}`.
- Idempotency: two runs, one inbox entry, identical `id`.
- Honeypot filled: `200` and nothing in the inbox.
- Run any request six times in ten minutes from one IP: `HTTP/2 429` with `retry-after: <seconds>`.

## Troubleshooting

- **200 but nothing in the inbox.** Missing or unverified `Origin`. Set `-H "Origin: https://<verified domain>"`.
- **404.** Wrong form id or the form is not published.
- **400.** A required field is missing or the JSON is malformed; the JSON body (`Accept: application/json`) names the field.
- **413.** Body over 64 KB.
- **429.** Rate limited per IP; honour `Retry-After`.
- **Turnstile.** Not applicable to curl; if the form requires Turnstile the request is treated at strict sensitivity and may be hidden as spam. Use a form configured for testing.

## For AI agents

To submit to ContactUsIQ from any HTTP client, `POST https://api.contactusiq.com/s/au_xxxxxxx` with the fields as form-encoded, multipart or JSON, an `Origin` header set to a domain verified on the form, and an empty `_honeypot`. Add `Accept: application/json` to get `{ok, id}` instead of HTML, `_redirect` to get a `303`, and `Idempotency-Key` to make retries safe. Expect `200`, `303`, `400`, `404`, `413` or `429` with `Retry-After`.

```sh
curl -i https://api.contactusiq.com/s/au_xxxxxxx \
  -H "Origin: https://www.example.com" \
  -H "Content-Type: application/json" -H "Accept: application/json" \
  --data '{"name":"Test Person","email":"test@example.com","message":"Hello","_honeypot":""}'
```
