*Cloud › Webhooks*

# Create or update a webhook

```http
PUT https://devapi.dispralabs.com/v1/cloud/projects/:prj/webhooks/:whk
```

Creates the webhook with the id you choose, or updates it. An empty `events` list receives every event. Deliveries are signed with the project's webhook secret.

Needs a key with `full` access.

- **Authentication:** Secret key (send it as `Authorization: Bearer <key>`)
- **Idempotency:** Safe to retry. Send an `Idempotency-Key` header and repeated calls within 24 hours return the first result.

## Parameters

- `prj` (string, required): The project's id. Example: `prj_01jdk3m9x2v7c4q8w5n6b1t0ra`
- `whk` (string, required): The webhook's id. Example: `whk_01jdk5j2k4l6z8x0c2v4b6n8mq`
- `url` (string, required): Where deliveries go. https only. Example: `https://hooks.acme.com/dispra`
- `events` (array, optional): The events to receive (default every event). Example: `["deploy.succeeded","deploy.failed"]`
- `enabled` (boolean, optional): False pauses it. Example: `true`

## Returns

- **201**: whk and status (created).
- **200**: whk and status (updated).

## Errors

| Status | Code | When |
|---|---|---|
| 404 | [not_found](https://docs.dispralabs.com/errors.md#not_found) | No such object in the key's project (or environment). |
| 400 | [invalid_url](https://docs.dispralabs.com/errors.md#invalid_url) | The URL is not https, or resolves to a private address. |

## Request samples

### Dispra Cloud CLI

```bash
dcloud api PUT /v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/webhooks/whk_01jdk5j2k4l6z8x0c2v4b6n8mq --data '{"url":"https://hooks.acme.com/dispra","events":["deploy.succeeded","deploy.failed"],"enabled":true}'
```

### cURL

```bash
curl -X PUT "https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/webhooks/whk_01jdk5j2k4l6z8x0c2v4b6n8mq" \
  -H "Authorization: Bearer dsp_live_YOUR_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://hooks.acme.com/dispra","events":["deploy.succeeded","deploy.failed"],"enabled":true}'
```

### Node

```javascript
const res = await fetch("https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/webhooks/whk_01jdk5j2k4l6z8x0c2v4b6n8mq", {
  method: "PUT",
  headers: { Authorization: "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
  body: JSON.stringify({
    "url": "https://hooks.acme.com/dispra",
    "events": ["deploy.succeeded","deploy.failed"],
    "enabled": true
  }),
});
console.log(await res.json());
```

### Python

```python
import uuid, requests
res = requests.request("PUT", "https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/webhooks/whk_01jdk5j2k4l6z8x0c2v4b6n8mq", headers={"Authorization": "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": str(uuid.uuid4())}, json={
  "url": "https://hooks.acme.com/dispra",
  "events": ["deploy.succeeded","deploy.failed"],
  "enabled": True
})
print(res.json())
```

### Go

```go
body := strings.NewReader(`{"url":"https://hooks.acme.com/dispra","events":["deploy.succeeded","deploy.failed"],"enabled":true}`)
req, _ := http.NewRequest("PUT", "https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/webhooks/whk_01jdk5j2k4l6z8x0c2v4b6n8mq", body)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer dsp_live_YOUR_KEY")
req.Header.Set("Idempotency-Key", uuid.NewString())
res, _ := http.DefaultClient.Do(req)
```

## Responses

### 201

```json
{}
```

### 200

```json
{}
```

### 404 not_found

```json
{
  "error": {
    "code": "not_found",
    "message": "No such object in the key's project (or environment).",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 400 invalid_url

```json
{
  "error": {
    "code": "invalid_url",
    "message": "The URL is not https, or resolves to a private address.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

## Related

- [Webhooks](https://docs.dispralabs.com/features/webhooks.md)
