Retrying failed webhooks | laravel-webhook-server | Spatie       

 SPATIE  

==

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-server](https://spatie.be/docs/laravel-webhook-server/v4)  Retrying failed webhooks

 Version   v4      

 Other versions for crawler [v4](https://spatie.be/docs/laravel-webhook-server/v4) 

  Retrying failed webhooks    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-server/v4/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-server/v4/installation-and-setup)
- [ Sending webhooks ](https://spatie.be/docs/laravel-webhook-server/v4/sending-webhooks)
- [ Signing requests ](https://spatie.be/docs/laravel-webhook-server/v4/signing-requests)
- [ Retrying failed webhooks ](https://spatie.be/docs/laravel-webhook-server/v4/retrying-failed-webhooks)
- [ Transport options ](https://spatie.be/docs/laravel-webhook-server/v4/transport-options)
- [ Events ](https://spatie.be/docs/laravel-webhook-server/v4/events)
- [ Testing webhooks ](https://spatie.be/docs/laravel-webhook-server/v4/testing-webhooks)
- [ Upgrading from v3 ](https://spatie.be/docs/laravel-webhook-server/v4/upgrading)

 Retrying failed webhooks
========================

###  On this page 

1. [ Response-aware retries ](#content-response-aware-retries)
2. [ Custom backoff strategies ](#content-custom-backoff-strategies)
3. [ Queue limits and final failures ](#content-queue-limits-and-final-failures)

A final response outside `2xx`, a connection failure, or a request exceeding the timeout fails the attempt. Redirects follow Guzzle's default redirect policy; a final `3xx` response fails too.

By default, the package makes three attempts in total. It waits 10 seconds before the second and 100 seconds before the third. The default exponential backoff then grows to 1,000 seconds and beyond when you configure more attempts, capped at 100,000 seconds.

Set `tries` and `timeout_in_seconds` in the config file, or override them using `maximumTries(5)` and `timeoutInSeconds(5)`.

Response-aware retries
--------------------------------------------------------------------------------------------------------------------------

The default policy retries every unsuccessful HTTP status. Limit retries, honor the receiver's minimum delay, and add full jitter with:

```
WebhookCall::create()
    ->url('https://other-app.com/webhooks')
    ->payload(['key' => 'value'])
    ->useSecret('your-shared-secret')
    ->retryOn([408, 425, 429, 500, 502, 503, 504])
    ->respectRetryAfter()
    ->withJitter()
    ->dispatch();
```

- `retryOn(null)` restores retrying all unsuccessful statuses.
- `retryOn([])` disables HTTP-status retries. Connection failures still retry.
- An excluded status immediately fires both `WebhookCallFailedEvent` and `FinalWebhookCallFailedEvent`, and honors `throwExceptionOnFailure()`.
- `respectRetryAfter()` accepts non-negative seconds or an HTTP date. Invalid values are ignored; past dates add no delay. The header never shortens the backoff.
- `withJitter()` chooses a random delay between zero and the backoff strategy's delay, inclusive. `Retry-After` is applied afterwards as a minimum.

Disable the last two options per call by passing `false`. The global config keys are `retryable_status_codes`, `respect_retry_after`, and `retry_with_jitter`. All three options are opt-in.

Custom backoff strategies
-----------------------------------------------------------------------------------------------------------------------------------

Implement `Spatie\WebhookServer\BackoffStrategy\BackoffStrategy` with a `waitInSecondsAfterAttempt(int $attempt): int` method returning a delay in seconds. Set the `backoff_strategy` config key to that class, or use `useBackoffStrategy(YourBackoffStrategy::class)` per call.

Queue limits and final failures
-----------------------------------------------------------------------------------------------------------------------------------------------------

Retries use delayed queue jobs, not immediate HTTP-client retries. Synchronous calls do not wait or loop. Make sure the resulting delay, including `Retry-After`, fits your queue driver's limits. Amazon SQS permits at most 15 minutes.

Listen to [webhook events](/docs/laravel-webhook-server/v4/events) to record failures. To mark the queue job as failed and rethrow the exception on the final failure, call `throwExceptionOnFailure()` or enable `throw_exception_on_failure` globally.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
