# cURL

Call Formerie from a shell, a cron job or a CI step with `curl` and `jq`. You don't need a Formerie package or an API key: a form's public address is all it takes.

## Submit a form

Paste this in a Bash terminal.

```bash
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"

curl --silent --show-error --max-time 10 \
  --request POST "$RUNTIME_URL/$FORM/submit" \
  --header "Content-Type: application/json" \
  --data '{
    "fields": {
      "name": "Jane Example",
      "email": "jane@example.com",
      "message": "Hello from my server"
    }
  }'
```

Replace `acme/contact`, on the marked line, with your own handles. A success is HTTP `202`, with a `submissionUid` such as `sub_p6dr8wq2j7tkan`: the answers are stored, and their email is queued. Each sample reads two optional settings from the environment, `FORMERIE_RUNTIME_URL` for a hostname you've connected, and `FORMERIE_FORM` for the handles.

## Before you start

1. [Publish a form](/guides/publish/), and take its workspace and form handles from the **Publish** tab. Your server doesn't need to be in the form's allowed websites.
2. To try things without emailing anyone, create a test key on the form's **Tests** tab, and put it in an environment variable called `FORMERIE_TEST_KEY`:

```bash
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"

# Keep the key out of your scripts. A test is stored apart and emails nobody.
curl --silent --show-error --max-time 10 \
  --request POST "$RUNTIME_URL/$FORM/submit" \
  --header "Content-Type: application/json" \
  --header "X-Formerie-Test-Key: $FORMERIE_TEST_KEY" \
  --data '{
    "fields": {
      "name": "Jane Example",
      "email": "jane@example.com",
      "message": "Just a test"
    }
  }'
```

A test comes back as `tst_...`, is stored apart, and emails nobody. A wrong key gets `TEST_KEY_INVALID`, HTTP `401`, and nothing is stored. Remove the header before you go live, since a key left in place files everything as a test. See [Test from a server or CI](/guides/test-your-form/#test-from-a-server-or-ci).

## Check answers without submitting

`validate` checks answers and stores nothing, so you can flag a problem early. It answers `200` when they pass, and `422` with the same errors as a submission when they don't. The final submission always checks the whole form again.

```bash
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"

# Stores nothing. Only the fields you send are checked.
curl --silent --show-error --max-time 10 \
  --request POST "$RUNTIME_URL/$FORM/validate" \
  --header "Content-Type: application/json" \
  --data '{
    "mode": "partial",
    "fields": {
      "email": "jane@example.com",
      "message": "hi"
    }
  }'
```

For a form with steps, name the step, and every field in it is checked:

```bash
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"

# Checks every field of that step, and nothing else.
curl --silent --show-error --max-time 10 \
  --request POST "$RUNTIME_URL/$FORM/validate" \
  --header "Content-Type: application/json" \
  --data '{
    "mode": "step",
    "step": "you",
    "fields": {
      "name": "Jane Example",
      "email": "jane@example.com"
    }
  }'
```

By default, only the fields you send are checked. A step the form doesn't have gets `BAD_REQUEST`.

## Show errors per field

Answers that fail come back as `VALIDATION_FAILED`, HTTP `422`, and nothing is stored. `error.fields` holds the problems by field, and `error.issues` holds the same ones in order. Each has a `path`, a `code` to match on, and a `message` that's safe to show, in the form's language.

```bash
# $answers holds the visitor's answers as JSON, and $shown is the path of the field to show.
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"

result=$(curl --silent --show-error --max-time 10 \
  --request POST "$RUNTIME_URL/$FORM/submit" \
  --header "Content-Type: application/json" \
  --data "$(jq -n --argjson fields "$answers" '{fields: $fields}')")

# One line for each problem: the field's path, then its message.
echo "$result" | jq -r '.error.issues[]? | "\(.path): \(.message)"'

# The answer at a path such as contact.email, and its first message, both safe for HTML.
answer=$(echo "$answers" | jq -r --arg path "$shown" 'getpath($path | split(".")) // "" | @html')
message=$(echo "$result" | jq -r --arg path "$shown" '.error.fields[$path][0].message // "" | @html')
html="<input name=\"$shown\" value=\"$answer\"><p class=\"error\">$message</p>"
```

A field inside a group has a path such as `contact.email`, and one inside a list has `guests[0].email`, so split the path to find its answer. See [Field paths](/guides/validation/#field-paths). Show the visitor's answers again with the messages, escaped, so they only have to fix what's wrong.

## Retry safely

A network failure doesn't tell you whether the submission arrived. So send one `metadata.idempotencyKey` per submission, the same on every retry. Formerie then counts and delivers it once, and answers a repeat with `DUPLICATE_SUBMISSION`, HTTP `409`, which means the first one worked.

```bash
# Takes a key to reuse as its first argument, and $message holds the answer to send.
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"
MAX_ATTEMPTS=3
LONGEST_WAIT=30

# One key per submission, the same on every retry. Keep it with the answers if you retry later.
key="${1:-$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)}"
body=$(jq -n --arg message "$message" --arg key "$key" '{
  fields: {name: "Jane Example", email: "jane@example.com", message: $message},
  metadata: {idempotencyKey: $key}
}')
headers=$(mktemp)
trap 'rm -f "$headers"' EXIT

answer() { # outcome-and-details as jq arguments
  jq -cn --arg key "$key" --argjson attempts "$attempt" "$@" '$ARGS.named'
}

pause() { # a little longer each time, and not after the last attempt
  if [ "$attempt" -lt "$MAX_ATTEMPTS" ]; then
    sleep "$attempt"
  fi
}

for attempt in $(seq 1 "$MAX_ATTEMPTS"); do
  if ! response=$(curl --silent --max-time 10 --dump-header "$headers" --write-out '\n%{http_code}' \
    --request POST "$RUNTIME_URL/$FORM/submit" \
    --header "Content-Type: application/json" \
    --data "$body"); then
    reason="network"
    pause
    continue
  fi

  status="${response##*$'\n'}"
  result="${response%$'\n'*}"
  after=$(tr -d '\r' <"$headers" | awk 'tolower($1) == "retry-after:" { print $2 }')

  # Only the short-term limit sends Retry-After. A form's own limit can last an hour, so don't wait for it.
  if [ "$status" = "429" ]; then
    reason="rate-limited"
    if [ -n "$after" ] && [ "$after" -le "$LONGEST_WAIT" ] && [ "$attempt" -lt "$MAX_ATTEMPTS" ]; then
      sleep "$after"
      continue
    fi
    answer --arg outcome retry-later --arg reason "$reason" --arg after "$after"
    exit 0
  fi

  # Something in front of Formerie may answer without JSON.
  if ! code=$(echo "$result" | jq -er 'if .ok then "OK" else .error.code end' 2>/dev/null); then
    reason="bad-response"
    case "$status" in
      502 | 503 | 504) pause; continue ;;
    esac
    answer --arg outcome retry-later --arg reason "$reason"
    exit 0
  fi

  case "$code" in
    OK)
      answer --arg outcome accepted --arg id "$(echo "$result" | jq -r .submissionUid)"
      exit 0
      ;;
    DUPLICATE_SUBMISSION)
      # The first send worked, and only its answer was lost.
      answer --arg outcome accepted --argjson duplicate true
      exit 0
      ;;
    FORM_MAINTENANCE | QUEUE_FAILED | INTERNAL_ERROR)
      reason="$code"
      pause
      continue
      ;;
    VALIDATION_FAILED)
      answer --arg outcome invalid --arg code "$code" --argjson issues "$(echo "$result" | jq -c .error.issues)"
      exit 0
      ;;
    *)
      answer --arg outcome rejected --arg code "$code" --arg message "$(echo "$result" | jq -r .error.message)"
      exit 0
      ;;
  esac
done

attempt=$MAX_ATTEMPTS
answer --arg outcome retry-later --arg reason "$reason"
```

| Answer | Retry? |
| --- | --- |
| No connection, or a timeout | Yes, with the same key |
| `429` with `Retry-After` | Yes, after that wait, if it's short. The short-term limit answers with `Retry-After: 60` |
| `429` with no `Retry-After` | No. A form's own limit can last an hour, so ask the visitor to try again later |
| `FORM_MAINTENANCE`, `QUEUE_FAILED`, `INTERNAL_ERROR` | Yes, after a short wait |
| `502`, `503` or `504` with no JSON | Yes. Something in front of Formerie answered |
| Any other answer with no JSON | No. Keep the key, and look into it |
| `DUPLICATE_SUBMISSION` | No. Treat it as a success |
| `VALIDATION_FAILED` and any other code | No. The answer won't change |

- The key must be a non-empty string. Anything else is ignored, and there's no repeat check.
- A repeat is noticed for 300 seconds by default, under the form's repeat window. See [What the repeat window covers](/guides/spam-protection/#what-the-repeat-window-covers).
- The check comes first, so a key that went through gets `DUPLICATE_SUBMISSION` even with different answers. Use a new key for each new submission. A key refused for its answers was never accepted, so it can go again once they're fixed.
- A retry after `QUEUE_FAILED` can store a second copy, which you'd see under **Submissions**. It's rare.

## Human verification

If your form requires human verification, use your own keys, with your site in the provider's list of domains and in the form's allowed websites. The widget adds its token to your form. Forward two things:

1. **The token,** as `verificationToken`, taken out of the fields.
2. **The `Origin` of the visitor's request,** because Formerie compares the token's domain with it. A server sends none by itself, and the check then fails with `TURNSTILE_FAILED`.

```bash
# $token is what your form sent as cf-turnstile-response, and $origin is the visitor's Origin header.
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"

# The token goes apart from the fields. Without the visitor's Origin, the provider's hostname can't match.
origin_header=()
if [ -n "$origin" ]; then
  origin_header=(--header "Origin: $origin")
fi

curl --silent --show-error --max-time 10 \
  --request POST "$RUNTIME_URL/$FORM/submit" \
  --header "Content-Type: application/json" \
  "${origin_header[@]}" \
  --data "$(jq -n --arg token "$token" '{
    fields: {name: "Jane Example", email: "jane@example.com", message: "Hello from my server"},
    verificationToken: $token
  }')"
```

An `Origin` that isn't in the form's allowed websites gets `FORBIDDEN_ORIGIN`. Only forward it for this: on any other form, it turns on a check your server doesn't otherwise need. The widget needs JavaScript in the visitor's browser. See [Verification on the server path](/guides/framework-entry-points/#verification-on-the-server-path).

## Spam checks

Hosted pages and embeds send this metadata for you. From your server, send it yourself, or those checks are skipped.

```bash
# $started_at is an ISO 8601 time, such as 2026-11-01T12:00:00Z, and $visitor_id is your own ID for the visitor.
RUNTIME_URL="${FORMERIE_RUNTIME_URL:-https://forms.formerie.com}"
# Your form. This is the only line that names it.
FORM="${FORMERIE_FORM:-acme/contact}"

# startedAt: when the visitor opened the form, for the minimum submit time check.
# deviceToken: your own visitor ID, for a limit rule with the deviceToken scope.
curl --silent --show-error --max-time 10 \
  --request POST "$RUNTIME_URL/$FORM/submit" \
  --header "Content-Type: application/json" \
  --data "$(jq -n \
    --arg key "$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)" \
    --arg started_at "$started_at" \
    --arg visitor_id "$visitor_id" '{
      fields: {name: "Jane Example", email: "jane@example.com", message: "Hello from my server"},
      metadata: {
        idempotencyKey: $key,
        startedAt: $started_at,
        pageUrl: "https://www.example.com/contact",
        deviceToken: $visitor_id
      }
    }')"
```

| Field | What it's for |
| --- | --- |
| `idempotencyKey` | The repeat check, as above |
| `startedAt` | When the visitor opened the form, as an ISO 8601 time. Sent sooner than the form's minimum, 1 second by default, it gets `SPAM_REJECTED`. Keep the real time from when you showed the form, not the time of this call. One that can't be read skips the check |
| `pageUrl` | The page the form was sent from. Stored only if it's an http or https address |
| `deviceToken` | Your own visitor ID, for a limit per visitor, below |

The hidden field check runs when your form sends that field, and links and human verification run on the server either way. See [Spam and limits](/guides/spam-protection/).

## Limits from your server

Formerie counts visitors by network address, and from here, that's your server's. **Every visitor counts as your server.**

| Limit | Default | From your server |
| --- | --- | --- |
| Per visitor | 30 submissions every 10 minutes | Shared by all your visitors. Raise it before you launch, or leave it empty for no limit, under **Settings**, then **Submission limits** |
| Whole form | 1,000 submissions an hour | The same. On the Free plan, it's also the most a form can accept |
| Short-term | 120 requests a minute for each form from one address | Can't be changed. It's the only one that sends `Retry-After`. `validate` counts here too |

Over any of them, you get `RATE_LIMITED`, HTTP `429`. To keep a limit for each visitor, a rule with the `deviceToken` scope counts by the ID you send, such as a hash of the visitor's address. The app's settings don't offer that rule yet, so [talk to us](https://formerie.com/contact/) to set one up, and keep the whole-form limit, since anyone calling the form directly can change their ID. See [Limits on the server path](/guides/framework-entry-points/#limits-on-the-server-path) for the reasoning, and [Plans and limits](/guides/plans-and-limits/) for monthly counts.

## Good to know

- Keep `--max-time` on every call, since `curl` waits as long as it takes otherwise.
- Keep test keys and answers out of your logs. A `requestId` in an error, or the `X-Request-Id` header, is what to log and to quote when you ask for help.
- Match on `error.code`, never on the message, since a form can reword its messages and a status can cover several codes. [Error codes](/guides/error-codes/) lists them all.

| With | Note |
| --- | --- |
| `--fail` | Leave it out. It hides the body of a `422`, which is where the field errors are. |
| `--retry` | It doesn't know about `DUPLICATE_SUBMISSION` or how long a form's own limit lasts, so the loop on this page is safer. |
| `jq` | Build the body with `jq -n`, as these samples do, so a quote in an answer can't break the JSON. |

The routes, fields and every error are in the [API reference](/guides/api-reference/).
