Getting files with webhooks

Use callback_url to get notified when orders change state, verify each webhook is genuine, and handle retries safely.

4 min read

Webhooks let us tell your system when an order changes state, so you don't have to keep asking. This guide covers how to set a callback_url, which events you'll receive, how to check a request really came from us, how retries work, and a simple handler flow you can copy.

How webhooks work here

When you place an order through the API, you can include an optional callback_url in the request body. It must be an https URL that your server controls. From then on, whenever that order moves to a new state, we send a POST request with a JSON body to that URL.

That's the whole idea. Instead of your script calling GET /orders/{id} every few minutes for hours, it sits quietly and reacts when we knock on the door. Fewer wasted requests, faster reactions, and one less loop to babysit.

Here's what the order body looks like with a callback set:

{
  "search_url": "https://app.apollo.io/#/people?...your filters...",
  "results_file_name": "Ops Managers Germany",
  "contact_count": 2500,
  "callback_url": "https://example.com/hooks/apollo-scraper"
}

If you haven't placed an API order before, start with Placing an order with the API.

The events you'll receive

Each webhook tells you what happened. The event name is in the X-ApolloScraper-Event header and in the JSON body. The ones you'll see most:

EventWhat it meansWhat you'd usually do
order.processingWe've started working on the order.Update a status field in your system, if you track it.
order.completedThe CSV is ready.Download the file and kick off whatever comes next.
order.cancelledThe order was cancelled.Mark it as cancelled and alert someone if it was unexpected.

The API documentation has the full list and the exact payload fields. Write your handler so it ignores event types it doesn't recognise, rather than crashing. That way it keeps working if new events appear later.

Verifying the signature

Your callback URL is reachable from the internet, which means anyone who finds it could send it a fake request. To stop someone tricking your system into downloading the wrong thing or marking orders complete, every webhook we send includes a signature header.

Conceptually, verification works like this:

  1. Read the raw request body exactly as it arrived, before parsing the JSON.
  2. Read the signature header from the request.
  3. Compute the expected signature from the raw body using your secret, following the method described in the API documentation.
  4. Compare the two using a constant-time comparison. If they don't match, reject the request with an error status and stop.

Two common mistakes to avoid. First, don't verify against re-serialised JSON. Parsing and re-encoding can change spacing or key order, and the signature won't match. Second, don't skip verification "just for now" in production. Temporary code has a habit of becoming permanent.

Tip: Also check the X-ApolloScraper-Event header matches the event in the body. It's a cheap sanity check that catches malformed requests early.

Retries and reliability

If your endpoint is down, times out, or returns an error, we'll retry the delivery a few times. That's helpful, but it also means you might receive the same event more than once. Plan for it.

  • Respond quickly. Return a success status as soon as you've verified and stored the event. Do the slow work (downloading, importing into your CRM) afterwards, in a background job.
  • Be idempotent. Use the order ID plus event name to check whether you've already handled this one. If you have, just return success again.
  • Have a fallback. If your server was offline for longer than the retries, nothing is lost. You can always call GET /orders/{id} to see the current status, and the file stays available in Orders for 180 days.

An example handler flow

Here's the shape of a typical handler, in plain steps you can translate into any language or automation tool:

  1. Receive the POST at your callback URL.
  2. Verify the signature against the raw body. If it fails, return an error and stop.
  3. Read the event name and order ID.
  4. Check your database: have you already processed this event for this order? If yes, return success and stop.
  5. Save the event and return success right away.
  6. In a background job, if the event is order.completed, call GET /orders/{id}/download with your API key and save the CSV.
  7. Pass the file on: import it to your CRM, drop it in shared storage, or notify the team.

A realistic example: a sales ops team submits a weekly order for "VP Sales, US, 200 to 1,000 employees". When order.completed arrives on Monday morning, their handler downloads the file, removes contacts already in the CRM, and posts a summary in their team chat. Nobody has to remember to check.

Testing before you go live

Place a small order with your callback URL pointing at a test endpoint, and log every request it receives, headers and body. Confirm you see order.processing and then order.completed, that verification passes, and that the download step works. Then switch to your real URL.

Questions about payloads or signature details? The API documentation has the specifics, and support@apolloscrapers.com is happy to help if something doesn't add up.

Still stuck?

Our team usually replies the same day.

Contact support
Get Apollo Export Files Automatically With Webhooks