> ## Documentation Index
> Fetch the complete documentation index at: https://cloud.laravel.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks for Laravel Cloud deployments

> Receive signed HTTP requests when a Laravel Cloud deployment goes live, succeeds, or fails, and verify that each request comes from Cloud.

Laravel Cloud can send a signed `POST` request to your own HTTPS endpoint when a deployment goes live, succeeds, or fails. Use webhooks to notify your team, start a job in another system, or record deployments in your own tools.

## Events

Each webhook subscribes to one or more of the following events. The event pages list every header and payload field:

| Event | Sent when |
| - | - |
| [`deployment.live`](https://cloud.laravel.com/docs/api/webhook-events/deployments/deployment-is-live) | Traffic switches to the new release. The deployment is still running, so its status is not final yet. |
| [`deployment.succeeded`](https://cloud.laravel.com/docs/api/webhook-events/deployments/deployment-succeeds) | The deployment succeeds. If the environment has post-deploy commands, they start at this point. |
| [`deployment.failed`](https://cloud.laravel.com/docs/api/webhook-events/deployments/deployment-fails) | The build or deploy fails, the deployment fails before its build starts, or a rollback fails. |
| [`deployment.post_deploy_failed`](https://cloud.laravel.com/docs/api/webhook-events/deployments/post-deploy-commands-fail) | The deployment is live, but its post-deploy commands failed or timed out. |

Cloud also sends a [`ping`](https://cloud.laravel.com/docs/api/webhook-events/other/ping) event when you [test an endpoint](#test-an-endpoint). Webhooks can't subscribe to `ping`.

Cloud sends no webhooks for patch deployments, which redeploy your current code onto an image patched for a security vulnerability.

## Create a webhook

An environment can have up to five webhooks. The endpoint URL must use HTTPS and resolve to a public address. When you create a webhook, Cloud generates a signing secret that starts with `whsec_`. You need it to [verify signatures](#verify-signatures).

> [tab] Dashboard
>
> 1. Open your environment's **Settings > Deployments** page.
> 2. In the **Deploy webhooks** section, click **New webhook**.
> 3. Enter the **Endpoint URL** and select the **Events** to send.
> 4. Click **Create**, then copy the signing secret.
>
> You can copy the secret again later from the webhook's **...** menu.

> [tab] API
>
> Send a request to the [create webhook endpoint](https://cloud.laravel.com/docs/api/webhooks/create-webhook-endpoint.md) endpoint with your API token:
>
> ```bash theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
> curl -X POST https://cloud.laravel.com/api/environments/ENVIRONMENT_ID/webhook-endpoints \
>   -H "Authorization: Bearer YOUR_API_TOKEN" \
>   -H "Accept: application/json" \
>   -H "Content-Type: application/json" \
>   -d '{"url": "https://example.com/webhooks/cloud", "events": ["deployment.succeeded", "deployment.failed"]}'
> ```
>
> The response contains the signing secret in `data.attributes.secret`. The API returns the secret only when you create a webhook or rotate its secret, so store it right away.

> [tab] MCP
>
> Ask your agent to add a webhook to an environment through the [MCP server](https://cloud.laravel.com/docs/mcp-server.md), for example: "Send failed deployments of my production environment to [https://example.com/webhooks/cloud](https://example.com/webhooks/cloud)." The agent uses the `create-webhook-endpoint` tool.
>
> Cloud returns the signing secret to your agent only when it specifically requests sensitive data. Otherwise, copy the secret from the dashboard.

## Requests

Cloud sends each event as a `POST` request with a JSON body and the following headers:

| Header | Value |
| - | - |
| `X-Cloud-Event` | The event type, such as `deployment.live`. It matches the body's `event` field. |
| `X-Cloud-Event-Id` | The event's identifier. It stays the same on every attempt to deliver the event. |
| `X-Cloud-Delivery` | The identifier of this delivery attempt. It's new on every attempt. |
| `X-Cloud-Timestamp` | When Cloud sent the attempt, as a Unix timestamp in seconds. |
| `X-Cloud-Signature` | `sha256=` followed by the request's signature. |

Cloud also sends `Content-Type: application/json` and `User-Agent: LaravelCloud-Webhooks/1.0`. The body is the same on every attempt and for every webhook that receives the event.

## Verify signatures

Verify every request before you act on it. To compute the signature, join the `X-Cloud-Timestamp` header, a period, and the raw request body, then hash the result with HMAC-SHA256, using the whole signing secret, including `whsec_`, as the key. The signature is valid when `sha256=` followed by the hex digest equals the `X-Cloud-Signature` header.

Read the raw body before your framework parses it, compare signatures in constant time, and reject old timestamps so that nobody can replay a captured request. The following examples read the secret from a `CLOUD_WEBHOOK_SECRET` environment variable (through a `services.cloud.webhook_secret` configuration value in Laravel PHP), and accept requests sent within the last five minutes:

```php Laravel PHP theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::post('/webhooks/cloud', function (Request $request) {
    $timestamp = $request->header('X-Cloud-Timestamp');
    $signature = $request->header('X-Cloud-Signature');
    $signed = $timestamp.'.'.$request->getContent();
    $secret = config('services.cloud.webhook_secret');

    $expected = 'sha256='.hash_hmac('sha256', $signed, $secret);

    abort_unless(is_string($signature) && hash_equals($expected, $signature), 403);
    abort_if(abs(time() - (int) $timestamp) > 300, 403);

    $event = $request->json()->all();

    // Handle the event...

    return response()->noContent();
})->withoutMiddleware(ValidateCsrfToken::class);
```

```js Node.js theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
import crypto from 'node:crypto';
import express from 'express';

const app = express();
const secret = process.env.CLOUD_WEBHOOK_SECRET;

app.post('/webhooks/cloud', express.raw({ type: 'application/json' }), (req, res) => {
    const timestamp = req.get('X-Cloud-Timestamp') ?? '';
    const signature = Buffer.from(req.get('X-Cloud-Signature') ?? '');

    const expected = Buffer.from(
        'sha256=' + crypto.createHmac('sha256', secret).update(`${timestamp}.`).update(req.body).digest('hex'),
    );

    if (signature.length !== expected.length || !crypto.timingSafeEqual(signature, expected)) {
        return res.sendStatus(403);
    }

    if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) {
        return res.sendStatus(403);
    }

    const event = JSON.parse(req.body);

    // Handle the event...

    res.sendStatus(204);
});
```

## Respond to a request

Return any `2xx` status code to acknowledge the request. Cloud waits up to 10 seconds for your endpoint to respond and doesn't follow redirects, so respond quickly and queue slow work, such as a background job, to run after you respond.

### Retries

Cloud tries to deliver each event up to five times. When your endpoint returns any other status code, including a redirect, or doesn't respond in time, Cloud retries the request after 10 seconds, 1 minute, 5 minutes, and 15 minutes. Cloud checks the endpoint URL again before every attempt and doesn't retry when its host can't be resolved or resolves to a private address.

Cloud delivers each event separately, so a retried event can arrive after a later one. Check the payload's `deployment.status` rather than relying on the order in which requests arrive.

### Duplicate requests

Your endpoint may receive the same event more than once, such as when Cloud retries a request your endpoint handled but didn't acknowledge in time. Every attempt at an event has the same `X-Cloud-Event-Id` header and a new `X-Cloud-Delivery` header. Store the event IDs you have handled and ignore requests with an ID you already processed.

### Disable a webhook from your endpoint

Return `410 Gone` to tell Cloud to stop sending requests to your endpoint. Cloud disables the webhook and drops its pending retries. To send events to it again, enable the webhook from the dashboard, or set `enabled` to `true` with the [update webhook endpoint](https://cloud.laravel.com/docs/api/webhooks/update-webhook-endpoint.md) endpoint.

## Test an endpoint

Send a `ping` event to check that your endpoint is reachable and verifies signatures. Cloud sends the test right away, doesn't retry it, and returns the result:

* In the dashboard, open the webhook and click **Test endpoint**.
* With the API, use the [send test webhook delivery](https://cloud.laravel.com/docs/api/webhooks/send-test-webhook-delivery.md) endpoint.
* With the MCP server, ask your agent to test the webhook. It uses the `ping-webhook-endpoint` tool.

## Review deliveries

Cloud keeps the 50 most recent delivery attempts for each webhook, with the request it sent and your endpoint's response or the error. Open the webhook's **Deliveries** tab in the dashboard to review them. To send an event again, select its delivery and click **Resend**. The new attempt has the same `X-Cloud-Event-Id`. You can also list deliveries with the [list webhook deliveries](https://cloud.laravel.com/docs/api/webhooks/list-webhook-deliveries.md) endpoint.

## Rotate the signing secret

Rotate the signing secret if it leaks, or as part of your regular secret rotation:

* In the dashboard, open the webhook and click **Rotate secret**.
* With the API, use the [rotate webhook endpoint secret](https://cloud.laravel.com/docs/api/webhooks/rotate-webhook-endpoint-secret.md) endpoint.
* With the MCP server, ask your agent to rotate the secret. It uses the `rotate-webhook-endpoint-secret` tool.

The previous secret stops working immediately, and Cloud signs every later attempt with the new secret, including retries of earlier events. Update the secret on your endpoint right after you rotate it.
