Sendcloud webhooks in production: duplicates, ordering, retries and timeouts

Published · Updated

This guide covers the problems Sendcloud webhooks can cause in production and how to handle each one. What Sendcloud sends is on the Sendcloud webhooks overview, the event types are on Sendcloud webhook events, and how to check the signature is on Verify Sendcloud webhooks.

It's about webhooks set on an integration. Sendcloud's beta Event Subscriptions API is a separate route, with its own events, authentication and retries.

At a glance

ProblemWhat to doWith Event Gateway
TimeoutsReturn a 2xx within 10 seconds; process in a background jobAccepts the event at once, then queues it for your service
DuplicatesBuild a key from action, the object's ID and timestampDrops repeats based on the body fields you choose
OrderingCompare timestamp with the latest you've stored per parcelLimits the delivery rate to your service
RetriesUse a 5xx for temporary problems; reconcile from the API after an outageAccepts events while your service is down and retries to it
Choosing eventsConfigure each integration; branch on action, then parcel.status.idFilters and routes on any field in the body
TestingUse Test API webhook, then record a real parcel updateForwards to localhost and replays past requests
Other limitsAllow for mixed date formats and unsigned timestampsVerifies the signature on each request

Sendcloud webhook timeouts and slow handlers

Your endpoint must return a 2xx within 10 seconds. Verify the signature, store the body and respond, then do the rest in a background job.

Why it happens: Parcel updates tend to start slow work, such as customer emails and order system calls. A request that passes 10 seconds counts as failed and is sent again, even if your handler finishes the work afterwards.

Fix it in your handler:

  1. Verify the signature, store the body and return 200 before anything else.
  2. Update orders and send customer messages in a worker. See why to process webhooks asynchronously.
  3. Keep calls to other services out of the request path.

With Event Gateway: Hookdeck accepts each Sendcloud event as it arrives, then queues it and delivers it to your service with its own retries. Your handler can take as long as it needs.

Duplicate Sendcloud webhooks

Make your handler idempotent with a key you build yourself, because Sendcloud's payload schemas have no event or delivery ID.

Why it happens: Sendcloud retries a request that timed out, so a slow handler can receive an update it has already processed. The docs don't say whether a retry is byte for byte the same, but they describe timestamp on a parcel update as the time the status changed, which makes it a useful part of the key.

Fix it in your handler:

  1. For parcel_status_changed, key on action, parcel.id, parcel.status.id and timestamp.
  2. For return_created, key on action and data.id.
  3. For the integration events, key on action, integration.id and timestamp.
  4. Skip any key you've already processed. See our guide to webhook idempotency.

With Event Gateway: Deduplication can drop repeats within a window of up to an hour, based on the fields you choose, before they reach your service.

Out-of-order Sendcloud webhooks

Webhooks can arrive out of order, so compare each payload's timestamp with the latest you've stored for that parcel before you apply it.

Why it happens: Sendcloud gives the example of an application that was unreachable for a while. Retries for an older status can then land after a newer status has been delivered.

Fix it in your handler:

  1. Store the latest timestamp per parcel and ignore any update older than it.
  2. Compare timestamp only with other timestamp values. The docs call it a Unix timestamp without giving the unit, and their one example, 1525271885993 on the integration events, is in milliseconds. Check the scale on a real delivery before you compare it with anything else.
  3. If an update matters to a customer and you're unsure, read the parcel from Sendcloud's API first.

carrier_status_change_timestamp is the time of the change in the carrier's system, and it can be null, so don't order on it.

With Event Gateway: A max delivery rate on your destination keeps a burst from reaching your handler all at once, and every request is stored, so you can inspect the sequence you received.

Sendcloud webhook retries and missed updates

Sendcloud makes up to 10 attempts over about an hour and a half, and only for some failures. A 400, 401, 404 or 422 stops delivery right away.

Why it happens: The first retry comes within 5 minutes, and the wait between later retries grows to roughly half an hour. Sendcloud sorts failures this way:

Your endpointWhat Sendcloud does
Times out or can't be reachedRetries
Returns 406, 408, 409 or 429Retries
Returns a 5xxRetries
Returns any other 4xxStops, with no retry

That means a broken route or a wrong signing key can lose updates on the first attempt. Every failed attempt is logged in the connection issue log. The docs describe no way to resend a failed delivery.

Fix it in your handler:

  1. Return a 5xx, such as 503, for anything temporary, like a database that's down.
  2. Keep other 4xx responses for requests you never want again, and alert on them.
  3. Check the connection issue log after any incident.
  4. After an outage or a run of 4xx responses, read the affected parcels from Sendcloud's API and update your records.

With Event Gateway: Hookdeck accepts each event as Sendcloud sends it, stores it and delivers it to your service with automatic retries on a schedule you control. Issues alert you when deliveries fail, and you can replay any stored request after an outage.

Choosing Sendcloud events

The docs describe no way to choose events: enable the webhook on an integration and branch on action. parcel_status_changed is the event most integrations are built around.

Why it happens: Webhooks are scoped to the integration they're configured on, which leaves some gaps:

  • Parcels created through another integration, such as a shop plugin, don't reach this integration's webhook.
  • Return parcels only send updates if the outgoing shipment was created through the API integration.
  • return_created fires for returns created through the API or the Return Portal, but not for returns created manually with the Return Form.

Fix it in your handler:

  1. Configure a webhook on every integration whose parcels you track, with a separate path for each so you know which key to use.
  2. Branch on action, then map parcel.status.id to your own states instead of parsing parcel.status.message.
  3. Keep your own copy of the status IDs. The v3 parcel statuses endpoint lists a code and a message with no ID, and only the legacy v2 endpoint lists IDs.
  4. Use parcel.is_return to handle return parcels separately, and find another source for returns made outside these routes.

With Event Gateway: Each integration can point at its own Hookdeck source with its own key, and all of them can feed one destination. Filters can route on action or parcel.status.id, so each service gets only what it handles.

Testing Sendcloud webhooks

Click Test API webhook in the integration's settings to send a test request, then create a parcel through the integration to see a real update.

Why you need both: The docs don't show what the test request contains. They publish schemas with field examples, but no complete body for any event, so your first real delivery is the best reference you'll have.

In your handler:

  1. Check your signature code against the docs' test vector, which is on Verify Sendcloud webhooks.
  2. Return a 2xx for an action you don't recognise, so the test request doesn't look like a failure.
  3. Record the body of your first parcel_status_changed and build your fixtures from it.

With Event Gateway: The Hookdeck CLI forwards requests to localhost, and you can replay stored requests without waiting for another status change.

Other Sendcloud limits

A few details of the signature and payloads can still trip a receiver that handles everything above.

The timestamp isn't signed. The signature covers only the body. timestamp is inside the body, but Sendcloud documents no replay window, so a replayed request verifies. Your idempotency key is what stops it having an effect.

Date formats differ within a parcel. date_created, date_updated and date_announced use DD-MM-YYYY HH:MM:SS in UTC, while delivery_dates uses ISO 8601. Don't pass them all to one parser.

carrier.id is reserved. It's always null, so identify the carrier with carrier.code.

Redirects are followed. Sendcloud sends the same request with the same body to the new URL, so a redirect won't break your signature check. Update the Webhook url anyway, so you don't depend on it.

No published source IPs. The webhook docs list no addresses to allow at a firewall, so rely on the signature.

With Event Gateway: Create a source with the Sendcloud type, enter your integration's key, and use the source URL as the Webhook url. Hookdeck verifies the signature on each request, and every request is listed with its headers and body.

Get started with Hookdeck for free and handle Sendcloud webhooks reliably in minutes.

Keep a bad deploy from losing Sendcloud parcel updates.

Sendcloud stops at the first 401 or 404 and gives up on an outage after about 90 minutes. Event Gateway verifies the signature, accepts each update and queues it for your service, so you can retry or replay it once your service is healthy.

Not affiliated with Sendcloud. Facts are compiled from public sources and linked inline.