Retry a scrape without paying for it twice
A request that times out may still have started the run. An idempotency key makes the retry safe: the same key gets the same run, never a second one.
API2 min read
By the EnrichedNow team
You start a run, the connection drops, and you never see the answer. Did the run start? You cannot tell from where you sit. Send the request again and you may start, and pay for, the same work twice. Do not send it and you may have nothing.
This is the oldest problem in calling a service over a network, and it has a standard answer: let the caller name the request, so the service can recognise a repeat.
Name the request
Add an Idempotency-Key header when you start a run. The key is any text of yours, up to 255 characters with no spaces. A new UUID for each run you mean to start is the usual choice.
curl -X POST "https://api.enrichednow.com/v1/scrapers/careers.company/runs" \
-H "Authorization: Bearer $ENRICHEDNOW_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 8f2c1c1e-0f1b-4a43-9a52-1c8a0b9a7e11" \
-d '{"input": {"domain": "northwind.example"}}'For 24 hours the API remembers which run that key started. What happens to a second request depends on what it asks for:
| You send | You get |
|---|---|
| The same key with the same request | The run the first request started, as it is now, with the header Idempotency-Replayed: true. Nothing new is started and nothing more is charged. |
| The same key with a different scraper or input | 409 with the code idempotency_conflict. The error names the run the key started. |
| A new key | A new run. |
A refused request keeps no key
If the first request was refused, no run exists, so there is nothing to replay. A request turned down because the input was invalid (422), the units were used up (402) or too many runs were in progress (429) leaves the key free. Fix the cause and send the same key again.
Two requests with one key that arrive at the same moment also start one run: the second waits for the first and gets its run back.
The packages do it for you
The Python, JavaScript, Go and Java packages send a key with every call that starts a run, a new one for each call. That is what lets them retry a start after a timeout or a server error, which they could not safely do before.
Pass your own key when the retry may come from a different process: a nightly job that is restarted halfway, a queue that delivers a message twice. Derive the key from the work itself, so the same piece of work always carries the same key.
from enrichednow import EnrichedNow
client = EnrichedNow() # reads ENRICHEDNOW_API_KEY
for domain in ["northwind.example", "tallgrass.example"]:
result = client.scrape(
"careers.company",
{"domain": domain},
idempotency_key=f"jobs-2026-11-19-{domain}",
)
print(domain, result.run.status, result.run.record_count)Run that script twice on the same day and the second pass costs nothing: each call gets the run the first pass started.
The details are in Running a scraper and the error codes in Errors.
Questions
- How long is an idempotency key remembered?
- 24 hours from the request that started the run. After that the same key starts a new run.
- Does a replayed request cost units?
- No. A replay returns the run the first request started. A run is charged once, when it ends ok or partial.
- Can two accounts use the same key?
- Yes. A key belongs to the account that sent it, so another account's keys never meet yours.