Code samples · curl

curl code samples

Copy-paste curl examples that validate one address, send the API key in the Authorization header, retry 429 and 503 answers after Retry-After when the wait is at most 10 seconds (never key_daily_cap, which lasts until the next UTC day), and report other errors with their code and request id. Each uses the free test address accepted@sandbox.email-validation.org; replace it with a real address when you are ready. The same samples in other languages: all code samples.

Set your key first: export EV_API_KEY="ev_live_…".

The samples call https://api.email-validation.org. For EU data residency, replace it with https://api-eu.email-validation.org; there /v1/validate takes POST only (EU data residency).

Validate an address

curl

# No --retry: curl would also resend after a timeout or a 500, 502 or 504, when the check may already have run and
# been charged. This loop resends only 429 and 503 (never charged), at most 3 attempts in all.
out=$(mktemp); hdr=$(mktemp)
for attempt in 1 2 3; do
  : > "$out"; : > "$hdr"
  code=$(curl -sS -o "$out" -D "$hdr" -w '%{http_code}' --max-time 20 \
    https://api.email-validation.org/v1/validate \
    -H "Authorization: Bearer $EV_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"email": "accepted@sandbox.email-validation.org"}')
  wait_s=$(awk 'tolower($1) == "retry-after:" { print $2 + 0 }' "$hdr")
  wait_s=${wait_s:-1}
  # never wait out a long Retry-After: key_daily_cap lasts until the next UTC day
  if { [ "$code" = 429 ] || [ "$code" = 503 ]; } && ! grep -q '"key_daily_cap"' "$out" \
    && [ "$wait_s" -le 10 ] && [ "$attempt" -lt 3 ]; then
    sleep "$wait_s"
    continue
  fi
  cat "$out"; echo   # the result, or the error with its code and request_id
  break
done
rm -f "$out" "$hdr"
[ "$code" = 200 ]   # the exit status: 0 only for a result

Read the credit balance

curl

curl https://api.email-validation.org/v1/credits -H "Authorization: Bearer $EV_API_KEY"

Create a bulk job

curl

# A CSV file with a header row; the email column is found automatically.
curl https://api.email-validation.org/v1/bulk \
  -H "Authorization: Bearer $EV_API_KEY" \
  -H "Content-Type: text/csv" \
  --data-binary @customers.csv

# Or a JSON list, without starting it yet:
curl "https://api.email-validation.org/v1/bulk?start=false" \
  -H "Authorization: Bearer $EV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"emails": ["accepted@sandbox.email-validation.org", "catch_all@sandbox.email-validation.org"]}'

Other calls

  • Verify a webhook: samples on Webhooks and in JavaScript, TypeScript, Python, PHP, Ruby, Go, Java and C# (all code samples).

Notes

  • Use POST with a JSON body; it keeps addresses out of URLs and logs.
  • Set the HTTP timeout to about 20 seconds: a check may take up to 15 seconds (10 by default).
  • A 200 answer with the status unknown is a normal, free result, not an error.
  • Every endpoint, field and error: the API reference.

Updated · Maintained by: Email Validation LLC

Need help? Contact support, or ask the help chat. Something wrong or missing on this page? Tell us