Skip to content

Commit 551c982

Browse files
authored
Merge pull request #27 from FoxNoseTech/feat/webhooks
feat: outbound webhooks support
2 parents e03ed57 + 4af82e3 commit 551c982

12 files changed

Lines changed: 2067 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This is the official Python SDK for FoxNose Management and Flux APIs.
1919
- **JWT authentication** - Built-in token refresh support
2020
- **Flux introspection** - Discover routes and live schema via `/_router` and `/_schema`
2121
- **FoxNose Files** - Upload links, analysis, review, policy and short-lived downloads
22+
- **Outbound webhooks** - Endpoints, signing secrets, the event log, redelivery and recovery
2223

2324
## Documentation
2425

@@ -190,6 +191,56 @@ client.update_resource("blog-posts", created["resource_key"], {"title": "Hello (
190191
client.close()
191192
```
192193

194+
### Webhooks
195+
196+
FoxNose sends a signed `POST` to your endpoint when a subscribed event happens. Endpoints and the event log run through the Management client, in sync and async alike.
197+
198+
```python
199+
from datetime import datetime, timedelta, timezone
200+
201+
endpoint = client.create_webhook_endpoint(
202+
url="https://hooks.example.com/foxnose",
203+
event_types=["revision.published", "resource.deleted"],
204+
collection_keys=["mK8nP3tYvBcX"], # omit for every collection
205+
payload_mode="content", # or "references" (the default)
206+
)
207+
store_secret(endpoint.secret) # also readable later with get_webhook_endpoint_secret
208+
209+
client.send_webhook_test_event(endpoint.id, "revision.published")
210+
211+
# After an outage: send the failed deliveries of the last day again.
212+
since = datetime.now(timezone.utc) - timedelta(days=1)
213+
while True:
214+
result = client.recover_webhook_deliveries(endpoint.id, since=since)
215+
if not result.more:
216+
break
217+
218+
# Or send one logged event to one endpoint again.
219+
client.redeliver_webhook_event("evt_01JCX3Q9W2B5V7RZ0D4K6M8P1T", endpoint_id=endpoint.id)
220+
```
221+
222+
| Call | What it does |
223+
|---|---|
224+
| `list_webhook_endpoints` / `create_webhook_endpoint` / `get_webhook_endpoint` / `update_webhook_endpoint` / `delete_webhook_endpoint` | Endpoints of the environment; a list carries `stats_24h` |
225+
| `list_webhook_endpoint_deliveries` | An endpoint's deliveries, each with the event it carries |
226+
| `get_webhook_endpoint_secret` / `rotate_webhook_endpoint_secret` | Read or replace the signing secret |
227+
| `send_webhook_test_event` | A sample event to one endpoint |
228+
| `recover_webhook_deliveries` | Send an endpoint's failed deliveries again |
229+
| `list_webhook_events` / `get_webhook_event` / `list_webhook_event_attempts` | The 30-day event log |
230+
| `redeliver_webhook_event` | Send a logged event again |
231+
| `list_webhook_event_types` | The event-type catalogue with JSON Schemas |
232+
233+
Deliveries follow [Standard Webhooks](https://www.standardwebhooks.com/), so the SDK has no verifier of its own: use a Standard Webhooks library with the endpoint's secret.
234+
235+
```python
236+
# pip install standardwebhooks
237+
from standardwebhooks.webhooks import Webhook
238+
239+
event = Webhook(secret).verify(request_body, request_headers) # raises on a bad signature
240+
```
241+
242+
`secret` of an endpoint is a credential: `repr()` of the secret models leaves it out, and it should stay out of logs. See the [Management client guide](https://foxnose-python.readthedocs.io/en/latest/management-client/#webhooks).
243+
193244
### Files
194245

195246
FoxNose Files takes uploads from end users and processes them for agents. Upload links and review run through the Management client, in sync and async alike.

‎docs/api-reference.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,62 @@ from foxnose_sdk import FolderRef, ResourceRef, RevisionRef
384384
heading_level: 4
385385
members: false
386386

387+
### Webhooks
388+
389+
::: foxnose_sdk.management.models.WebhookEndpoint
390+
options:
391+
show_source: false
392+
heading_level: 4
393+
members: false
394+
395+
::: foxnose_sdk.management.models.WebhookEndpointCreated
396+
options:
397+
show_source: false
398+
heading_level: 4
399+
members: false
400+
401+
::: foxnose_sdk.management.models.WebhookSecretRotation
402+
options:
403+
show_source: false
404+
heading_level: 4
405+
members: false
406+
407+
::: foxnose_sdk.management.models.WebhookEndpointDelivery
408+
options:
409+
show_source: false
410+
heading_level: 4
411+
members: false
412+
413+
::: foxnose_sdk.management.models.WebhookEvent
414+
options:
415+
show_source: false
416+
heading_level: 4
417+
members: false
418+
419+
::: foxnose_sdk.management.models.WebhookEventDetail
420+
options:
421+
show_source: false
422+
heading_level: 4
423+
members: false
424+
425+
::: foxnose_sdk.management.models.WebhookAttempt
426+
options:
427+
show_source: false
428+
heading_level: 4
429+
members: false
430+
431+
::: foxnose_sdk.management.models.WebhookRedeliveryResult
432+
options:
433+
show_source: false
434+
heading_level: 4
435+
members: false
436+
437+
::: foxnose_sdk.management.models.WebhookEventType
438+
options:
439+
show_source: false
440+
heading_level: 4
441+
members: false
442+
387443
### Permissions
388444

389445
::: foxnose_sdk.management.models.MyPermissions

‎docs/changelog.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- **Outbound webhooks** on `ManagementClient` and `AsyncManagementClient`, with typed responses:
13+
- Endpoints: `list_webhook_endpoints` (items carry `stats_24h`), `create_webhook_endpoint`, `get_webhook_endpoint`, `update_webhook_endpoint`, `delete_webhook_endpoint`, `list_webhook_endpoint_deliveries`.
14+
- Signing secrets: `get_webhook_endpoint_secret`, `rotate_webhook_endpoint_secret`.
15+
- Test and recovery: `send_webhook_test_event`, `recover_webhook_deliveries`.
16+
- Event log: `list_webhook_events`, `get_webhook_event`, `list_webhook_event_attempts`, `redeliver_webhook_event`, and `list_webhook_event_types` for the catalogue with JSON Schemas.
17+
- `WebhookEndpointNotFound` (404 `webhook_endpoint_not_found`), `WebhookEventNotFound` (404 `webhook_event_not_found`), `WebhookEndpointLimitExceeded` (409 `limit_exceeded`), `WebhookEndpointNotActive` (409 `endpoint_not_active`, with `reason` and `skipped` for a redelivery) and `WebhookEndpointNotSubscribed` (409 `endpoint_not_subscribed`, with `skipped` for a redelivery), subclasses of `FoxnoseAPIError`.
18+
- `repr()` of the secret models leaves out the signing secret, and so does a response that fails to parse. The SDK does not verify signatures: deliveries follow Standard Webhooks, so use a Standard Webhooks library.
19+
1020
## [0.9.0] - 2026-11-17
1121

1222
### Added

‎docs/error-handling.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ subclasses of `FoxnoseAPIError`:
8383
| `ExternalIdConflict` | 409 `external_id_conflict` | The supplied `key` already identifies a resource. |
8484
| `ContentValidationFailed` | 422 `content_validation_failed` | Exposes `errors` (each with a `json_path`) and `errors_truncated`. |
8585
| `UpstreamError` | 502 `upstream_error` | The write's outcome is unknown — verify with a GET before retrying. |
86+
| `WebhookEndpointNotFound` | 404 `webhook_endpoint_not_found` | No endpoint with this id in the environment. |
87+
| `WebhookEventNotFound` | 404 `webhook_event_not_found` | No such event within the last 30 days. |
88+
| `WebhookEndpointLimitExceeded` | 409 `limit_exceeded` | The environment already has 20 webhook endpoints. |
89+
| `WebhookEndpointNotActive` | 409 `endpoint_not_active` | The endpoint is paused, disabled or deleted. `reason` is set when a redelivery names the endpoint, and `skipped` when a redelivery without `endpoint_id` finds none to send to. |
90+
| `WebhookEndpointNotSubscribed` | 409 `endpoint_not_subscribed` | The endpoint's event types or collection filter do not cover the event. `skipped` is set when a redelivery without `endpoint_id` finds only endpoints that do not cover the event. |
8691

8792
```python
8893
from foxnose_sdk import (

‎docs/index.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Official Python client for FoxNose Management and Flux APIs.
1010
- **JWT authentication** - Built-in support for JWT tokens with automatic refresh
1111
- **Flexible identifiers** - Pass string keys or model objects directly to any method
1212
- **FoxNose Files** - Upload links, analysis, review, policy and short-lived downloads
13+
- **Outbound webhooks** - Endpoints, signing secrets, the event log, redelivery and recovery
1314
- **Comprehensive coverage** - Access to all Management and Flux API endpoints
1415

1516
## Installation
@@ -53,6 +54,7 @@ For administrative operations:
5354
- Configuring roles, permissions, and API keys
5455
- Managing organizations, projects, and environments
5556
- Upload links, review and downloads for FoxNose Files
57+
- Webhook endpoints, the event log, redelivery and recovery
5658

5759
### FluxClient
5860

‎docs/management-client.md‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,85 @@ tombstones = client.list_file_tombstones("attachments", params={"limit": 20})
722722

723723
`update_files_policy` takes a `FilesPolicyBody` or a mapping and replaces the policy: an omitted field takes its default. `version` is `None` while the collection runs on the default policy.
724724

725+
## Webhooks
726+
727+
An endpoint is a URL that receives a signed `POST` when a subscribed event happens in the environment. The calls need the `webhooks` permission: `read` to list and read, `create`, `update` for every action on an endpoint, `delete`.
728+
729+
### Endpoints
730+
731+
```python
732+
from datetime import datetime, timedelta, timezone
733+
734+
endpoint = client.create_webhook_endpoint(
735+
url="https://hooks.example.com/foxnose",
736+
event_types=["revision.published", "resource.deleted"],
737+
collection_keys=["mK8nP3tYvBcX"], # omit for every collection
738+
payload_mode="content", # or "references" (the default)
739+
)
740+
store_secret(endpoint.secret) # also readable later with get_webhook_endpoint_secret
741+
742+
client.send_webhook_test_event(endpoint.id, "revision.published")
743+
744+
# After an outage: send the failed deliveries of the last day again.
745+
since = datetime.now(timezone.utc) - timedelta(days=1)
746+
while True:
747+
result = client.recover_webhook_deliveries(endpoint.id, since=since)
748+
if not result.more:
749+
break
750+
751+
# Or send one logged event to one endpoint again.
752+
client.redeliver_webhook_event("evt_01JCX3Q9W2B5V7RZ0D4K6M8P1T", endpoint_id=endpoint.id)
753+
```
754+
755+
`create_webhook_endpoint` needs `url` and `event_types`; `collection_keys` takes keys or collection models. `update_webhook_endpoint` sends only the fields given, and `status="active"` resumes a paused or disabled endpoint. `list_webhook_endpoints` takes `status`, `limit` (at most 200) and `offset` in `params`; each item carries `stats_24h` (`attempts` and `succeeded` of the last 24 hours).
756+
757+
### Secrets
758+
759+
```python
760+
current = client.get_webhook_endpoint_secret(endpoint.id)
761+
rotation = client.rotate_webhook_endpoint_secret(endpoint.id)
762+
print(rotation.previous_secret_expires_at) # the old secret signs for 24 hours
763+
client.rotate_webhook_endpoint_secret(endpoint.id, expire_previous_now=True)
764+
```
765+
766+
`secret` of an endpoint is a credential: `repr()` of the secret models leaves it out, and it should stay out of logs. A response that fails to parse does not quote it either.
767+
768+
### Verifying a delivery
769+
770+
Deliveries follow [Standard Webhooks](https://www.standardwebhooks.com/), so the SDK has no verifier of its own: use a Standard Webhooks library with the endpoint's secret.
771+
772+
```python
773+
# pip install standardwebhooks
774+
from standardwebhooks.webhooks import Webhook
775+
776+
event = Webhook(secret).verify(request_body, request_headers) # raises on a bad signature
777+
```
778+
779+
### Event Log
780+
781+
```python
782+
events = client.list_webhook_events(params={"type": "revision.published", "after": "2026-11-10T00:00:00Z"})
783+
detail = client.get_webhook_event(events.results[0].id) # envelope and deliveries
784+
attempts = client.list_webhook_event_attempts(detail.id)
785+
786+
deliveries = client.list_webhook_endpoint_deliveries(endpoint.id)
787+
types = client.list_webhook_event_types() # with the JSON Schema of each payload mode
788+
```
789+
790+
`list_webhook_events` takes `type`, `endpoint`, `status` (`pending`, `succeeded` or `dead`), `test`, `after`, `before`, `limit` and `offset` in `params`. The log keeps 30 days. `redeliver_webhook_event` returns the new `deliveries` and the endpoints it `skipped`. `response_excerpt` of an attempt is left out of `repr()`.
791+
792+
### Webhook Errors
793+
794+
| Exception | Status / code |
795+
|---|---|
796+
| `WebhookEndpointNotFound` | 404 `webhook_endpoint_not_found` |
797+
| `WebhookEventNotFound` | 404 `webhook_event_not_found` |
798+
| `WebhookEndpointLimitExceeded` | 409 `limit_exceeded` (20 endpoints per environment) |
799+
| `WebhookEndpointNotActive` | 409 `endpoint_not_active`; a redelivery adds `reason` or `skipped` |
800+
| `WebhookEndpointNotSubscribed` | 409 `endpoint_not_subscribed`; a redelivery without `endpoint_id` adds `skipped` |
801+
802+
A rejected request body is a `400` `FoxnoseAPIError`: `error_code` is the code (`invalid_url`, `unknown_event_type`, `unknown_collection`, ...) and `detail` says what is wrong when there is something to say: `field`, and for example `unknown` or `reason`.
803+
725804
## My Permissions
726805

727806
`get_my_permissions` says what the authenticated caller may do in the environment. It works for a user token and for a Management API key of this environment.

‎src/foxnose_sdk/__init__.py‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
RateLimitExceeded,
3030
SpendCapExceeded,
3131
UpstreamError,
32+
WebhookEndpointNotFound,
33+
WebhookEventNotFound,
34+
WebhookEndpointLimitExceeded,
35+
WebhookEndpointNotActive,
36+
WebhookEndpointNotSubscribed,
3237
)
3338
from .flux.client import AsyncFluxClient, FluxClient
3439
from .flux.models import (
@@ -149,6 +154,31 @@
149154
EnvironmentAccess,
150155
ContentTypeAccess,
151156
MyPermissions,
157+
WebhookStats24h,
158+
WebhookEndpoint,
159+
WebhookEndpointList,
160+
WebhookEndpointCreated,
161+
WebhookSecret,
162+
WebhookSecretRotation,
163+
WebhookEndpointRef,
164+
WebhookDelivery,
165+
WebhookDeliveryEvent,
166+
WebhookEndpointDelivery,
167+
WebhookEndpointDeliveryList,
168+
WebhookDeliveryCounts,
169+
WebhookEvent,
170+
WebhookEventList,
171+
WebhookEventDetail,
172+
WebhookAttempt,
173+
WebhookAttemptList,
174+
WebhookTestEvent,
175+
WebhookRecovery,
176+
WebhookRedelivery,
177+
WebhookSkippedEndpoint,
178+
WebhookRedeliveryResult,
179+
WebhookEventSchemas,
180+
WebhookEventType,
181+
WebhookEventTypeList,
152182
FileOrigin,
153183
FileOriginActor,
154184
FileOriginLink,
@@ -180,6 +210,11 @@
180210
"ExternalIdConflict",
181211
"ContentValidationFailed",
182212
"UpstreamError",
213+
"WebhookEndpointNotFound",
214+
"WebhookEventNotFound",
215+
"WebhookEndpointLimitExceeded",
216+
"WebhookEndpointNotActive",
217+
"WebhookEndpointNotSubscribed",
183218
"ManagementClient",
184219
"AsyncManagementClient",
185220
"FluxClient",
@@ -295,6 +330,31 @@
295330
"EnvironmentAccess",
296331
"ContentTypeAccess",
297332
"MyPermissions",
333+
"WebhookStats24h",
334+
"WebhookEndpoint",
335+
"WebhookEndpointList",
336+
"WebhookEndpointCreated",
337+
"WebhookSecret",
338+
"WebhookSecretRotation",
339+
"WebhookEndpointRef",
340+
"WebhookDelivery",
341+
"WebhookDeliveryEvent",
342+
"WebhookEndpointDelivery",
343+
"WebhookEndpointDeliveryList",
344+
"WebhookDeliveryCounts",
345+
"WebhookEvent",
346+
"WebhookEventList",
347+
"WebhookEventDetail",
348+
"WebhookAttempt",
349+
"WebhookAttemptList",
350+
"WebhookTestEvent",
351+
"WebhookRecovery",
352+
"WebhookRedelivery",
353+
"WebhookSkippedEndpoint",
354+
"WebhookRedeliveryResult",
355+
"WebhookEventSchemas",
356+
"WebhookEventType",
357+
"WebhookEventTypeList",
298358
"FileOrigin",
299359
"FileOriginActor",
300360
"FileOriginLink",

0 commit comments

Comments
 (0)