Code samples

Code samples

Copy-paste examples that validate one address and send the API key in the Authorization header. They retry 429 and 503 responses when Retry-After asks for a wait of 10 seconds or less. They never retry key_daily_cap, which lasts until the next UTC day. Other errors are reported 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.

Languages
12
Official SDKs
14
Validate one address with 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"}')
  rc=$?
  # curl failed (timeout, dropped connection): not resent, the check may already be charged
  if [ "$rc" -ne 0 ]; then echo "curl failed with exit code $rc" >&2; code=000; break; fi
  wait_s=$(awk 'tolower($1) == "retry-after:" { print $2 + 0 }' "$hdr")
  wait_s=${wait_s:-1}
  # only our JSON error (it has a request_id) is resent; never key_daily_cap (it lasts until the next UTC day)
  if { [ "$code" = 429 ] || [ "$code" = 503 ]; } && grep -q '"request_id"' "$out" && ! 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

Choose a language to see its code samples:

LanguageSamples
curlvalidate, credit balance, bulk job
JavaScriptvalidate, credit balance, bulk job, webhook
TypeScriptSDK, validate, webhook
PythonSDK, validate, credit balance, bulk job, webhook
PHPSDK, validate, webhook
RubySDK, validate, webhook
GoSDK, validate, webhook
JavaSDK, validate, webhook
C#SDK, validate, webhook
RustSDK, validate, webhook
SwiftSDK, validate, webhook
KotlinSDK, validate

Set your key first, without saving it in your shell history: quickstart step 1 shows how on macOS, Linux and Windows PowerShell (5.1 and 7).

The samples call https://api.email-validation.org. For EU data residency, replace it with https://api-eu.email-validation.org, or pass the SDK's EU base URL constant. On the EU host, /v1/validate accepts only POST (EU data residency).

With an official SDK

The official SDKs (8 published, 6 coming soon) handle retries and timeouts for you. One call validates an address, and every failure arrives as a typed error. There are official SDKs for JavaScript/TypeScript, Python, Go, PHP, Ruby, C#, Rust and Swift; those for Java, Kotlin, Dart, Elixir, C and Perl are built and tested and coming soon to their package registries. The plain HTTP samples call the API directly.

Samples in TypeScript, Python, PHP, Ruby, Go, Java, C#, Rust, Swift and Kotlin. See the SDK pages for Dart, Elixir, C and Perl.

Validate an address

Samples in curl, JavaScript, TypeScript, Python, PHP, Ruby, Go, Java, C#, Rust, Swift and Kotlin.

Read the credit balance

Samples in curl, JavaScript and Python.

Create a bulk job

Samples in curl, JavaScript and Python.

Verify a webhook

Samples in JavaScript, TypeScript, Python, PHP, Ruby, Go, Java, C#, Rust and Swift.

The same webhook samples are also on Webhooks.

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 response with the status unknown is a normal result, not an error, and it is free.
  • The official SDKs (8 published, 6 coming soon) do all of this for you, in every language above except curl.

Updated · Maintained by: Email Validation LLC

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