You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 551c982
Browse filesBrowse the repository at this point in the historyBrowse files
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
|`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
+
193
244
### Files
194
245
195
246
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.
- 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.
Copy file name to clipboardExpand all lines: docs/error-handling.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,11 @@ subclasses of `FoxnoseAPIError`:
83
83
|`ExternalIdConflict`| 409 `external_id_conflict`| The supplied `key` already identifies a resource. |
84
84
|`ContentValidationFailed`| 422 `content_validation_failed`| Exposes `errors` (each with a `json_path`) and `errors_truncated`. |
85
85
|`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. |
`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.
724
724
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
`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)
`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
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()`.
|`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
+
725
804
## My Permissions
726
805
727
806
`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.
0 commit comments