When validating large email lists, polling for batch results is inefficient. Use the webhook_url parameter to receive results asynchronously when the batch completes.
1. Submit a batch request with a webhook_url 2. The API accepts the request immediately and returns a job ID 3. Emailyze processes the batch asynchronously 4. When complete, Emailyze sends an HTTP POST to your webhook_url with the full results 5. Your endpoint responds with 200 to acknowledge
POST /v1/check/batch/
{
"emails": ["[email protected]", "[email protected]", ...],
"webhook_url": "https://yourapp.com/webhooks/emailyze"
}
Response:
{ "job_id": "job_abc123", "status": "processing", "count": 500 }
When the batch completes, your endpoint receives:
{
"job_id": "job_abc123",
"status": "completed",
"processed": 500,
"results": [
{
"email": "[email protected]",
"domain": "tempmail.com",
"is_disposable": true,
"provider_type": "disposable",
"risk_score": 91,
"mx_valid": false
},
...
],
"completed_at": "2025-03-05T12:00:00Z"
}
Emailyze signs webhook payloads with an HMAC-SHA256 signature using your webhook secret. Always verify the signature before processing.
import hmac
import hashlib
def verify_signature(payload: bytes, signature: str, secret: str) -> bool:
expected = hmac.new(
secret.encode(), payload, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, signature)
# In your Django/Flask view
def webhook_handler(request):
signature = request.headers.get("X-Emailyze-Signature", "")
if not verify_signature(request.body, signature, WEBHOOK_SECRET):
return HttpResponse(status=401)
data = json.loads(request.body)
process_results(data["results"])
return HttpResponse(status=200)
// Node.js / Express
const crypto = require("crypto");
function verifySignature(payload, signature, secret) {
const expected = crypto
.createHmac("sha256", secret)
.update(payload)
.digest("hex");
return crypto.timingSafeEqual(
Buffer.from(expected),
Buffer.from(signature)
);
}
app.post("/webhooks/emailyze", express.raw({ type: "application/json" }), (req, res) => {
const sig = req.headers["x-emailyze-signature"];
if (!verifySignature(req.body, sig, process.env.EMAILYZE_WEBHOOK_SECRET)) {
return res.status(401).end();
}
const data = JSON.parse(req.body);
// process data.results
res.status(200).end();
});
If your webhook endpoint returns a non-2xx status or times out, Emailyze retries with exponential backoff:
| Attempt | Delay | |---------|-------| | 1st retry | 1 minute | | 2nd retry | 5 minutes | | 3rd retry | 30 minutes | | 4th retry | 2 hours |
After 4 failed retries, the webhook is marked as failed. You can retrieve results via polling as a fallback.
Your webhook handler may receive the same job_id more than once (due to retries). Make your handler idempotent by checking whether you've already processed a given job_id:
processed_jobs = set() # Use Redis/DB in production
def process_webhook(data):
job_id = data["job_id"]
if job_id in processed_jobs:
return # Already handled
processed_jobs.add(job_id)
# Process data["results"]
Use webhook.site or ngrok to expose your local server:
# ngrok
ngrok http 8000
# Use the HTTPS forwarding URL as your webhook_url
# e.g. https://abc123.ngrok.io/webhooks/emailyze
import requests
def submit_batch_job(emails: list[str], webhook_url: str, api_key: str) -> str:
resp = requests.post(
"https://api.emailyze.xyz/v1/check/batch/",
headers={"X-API-Key": api_key, "Content-Type": "application/json"},
json={"emails": emails, "webhook_url": webhook_url},
)
resp.raise_for_status()
return resp.json()["job_id"]
# Django webhook receiver
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import json, hmac, hashlib
@csrf_exempt
def emailyze_webhook(request):
if request.method != "POST":
return HttpResponse(status=405)
sig = request.headers.get("X-Emailyze-Signature", "")
secret = settings.EMAILYZE_WEBHOOK_SECRET
expected = hmac.new(secret.encode(), request.body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, sig):
return HttpResponse(status=401)
data = json.loads(request.body)
for result in data["results"]:
if result["is_disposable"]:
# Flag user in database, send alert, etc.
pass
return HttpResponse(status=200)