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

Agent skill: `npx skills add hookdeck/webhook-skills --skill sendcloud-webhooks` ([details](https://hookdeck.com/webhooks/sendcloud/skill))

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](/webhooks/sendcloud) overview, the event types are on [Sendcloud webhook events](/webhooks/sendcloud/events), and how to check the signature is on [Verify Sendcloud webhooks](/webhooks/sendcloud/verify).

It's about webhooks set on an integration. Sendcloud's beta [Event Subscriptions API](https://sendcloud.dev/api/v3/event-subscriptions/index) is a separate route, with its own events, authentication and retries.

## At a glance

| Problem | What to do | With Event Gateway |
| --- | --- | --- |
| [Timeouts](#timeouts) | Return a 2xx within 10 seconds; process in a background job | Accepts the event at once, then queues it for your service |
| [Duplicates](#duplicates) | Build a key from `action`, the object's ID and `timestamp` | Drops repeats based on the body fields you choose |
| [Ordering](#ordering) | Compare `timestamp` with the latest you've stored per parcel | Limits the delivery rate to your service |
| [Retries](#retries) | Use a 5xx for temporary problems; reconcile from the API after an outage | Accepts events while your service is down and retries to it |
| [Choosing events](#choosing-events) | Configure each integration; branch on `action`, then `parcel.status.id` | Filters and routes on any field in the body |
| [Testing](#testing) | Use Test API webhook, then record a real parcel update | Forwards to localhost and replays past requests |
| [Other limits](#other-limits) | Allow for mixed date formats and unsigned timestamps | Verifies the signature on each request |

## Sendcloud webhook timeouts and slow handlers {#timeouts}

Your endpoint must return a 2xx [within 10 seconds](https://sendcloud.dev/api/v3/webhooks#retry-behavior). 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](/webhooks/guides/why-implement-asynchronous-processing-webhooks).
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](/docs/retries). Your handler can take as long as it needs.

## Duplicate Sendcloud webhooks {#duplicates}

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](/webhooks/guides/implement-webhook-idempotency).

**With Event Gateway:** [Deduplication](/docs/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 {#ordering}

[Webhooks can arrive out of order](https://sendcloud.dev/api/v3/webhooks), 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](/docs/destinations#set-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 {#retries}

Sendcloud makes [up to 10 attempts over about an hour and a half](https://sendcloud.dev/api/v3/webhooks#retry-behavior), 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 endpoint | What Sendcloud does |
| --- | --- |
| Times out or can't be reached | Retries |
| Returns `406`, `408`, `409` or `429` | Retries |
| Returns a 5xx | Retries |
| Returns any other 4xx | Stops, 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](https://app.sendcloud.com/v2/settings/integrations/logs). 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](/docs/retries) on a schedule you control. [Issues](/docs/issues) alert you when deliveries fail, and you can replay any stored request after an outage.

## Choosing Sendcloud events {#choosing-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](https://sendcloud.dev/api/v3/parcel-statuses/retrieve-a-list-of-parcel-statuses) lists a `code` and a `message` with no ID, and only the [legacy v2 endpoint](https://sendcloud.dev/api/v2/parcel-statuses/retrieve-a-list-of-parcel-statuses) 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](/docs/filters) can route on `action` or `parcel.status.id`, so each service gets only what it handles.

## Testing Sendcloud webhooks {#testing}

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](/webhooks/sendcloud/verify).
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](/docs/cli) forwards requests to localhost, and you can replay stored requests without waiting for another status change.

## Other Sendcloud limits {#other-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](https://dashboard.hookdeck.com/signup) for free and handle Sendcloud webhooks reliably in minutes.