55from linkedapi .errors import LinkedApiError
66from linkedapi .http import HttpClient
77from linkedapi .types .webhooks import (
8+ DeleteWebhookHeaderParams ,
89 DeleteWebhookParams ,
910 ReplayWebhookDeliveryParams ,
11+ RevealWebhookSecretParams ,
12+ RotateWebhookSecretParams ,
13+ SetWebhookEventsParams ,
14+ SetWebhookHeaderParams ,
15+ SetWebhookHeadersParams ,
1016 SetWebhookParams ,
1117 SetWebhookPayloadModeParams ,
18+ SetWebhookSigningParams ,
1219 WebhookDelivery ,
1320 WebhookSubscription ,
1421)
1724class AdminWebhooks :
1825 """Manage the client's registered outbound webhook and inspect recent deliveries.
1926
20- A client may hold at most one active webhook. It receives every event Linked API emits
21- (workflow lifecycle + account status changes); filter by the event ``type`` on your receiver.
27+ A client may hold at most one active webhook. Its event selectors control which workflow,
28+ account, inbox and network events it receives; None selects all events. Test events are
29+ always delivered. Signing and custom headers are configured per subscription.
2230 """
2331
2432 def __init__ (self , http_client : HttpClient [Any ]) -> None :
@@ -40,6 +48,78 @@ def set_payload_mode(self, params: SetWebhookPayloadModeParams) -> WebhookSubscr
4048 )
4149 return WebhookSubscription .model_validate (result ["webhook" ])
4250
51+ def set_signing (self , params : SetWebhookSigningParams ) -> WebhookSubscription :
52+ """Enable or disable signing. Enabling returns the stored secret."""
53+ result = self ._post_result (
54+ "/admin/webhook.setSigning" ,
55+ "Failed to set webhook signing" ,
56+ params ,
57+ )
58+ return WebhookSubscription .model_validate (result ["webhook" ])
59+
60+ def set_headers (self , params : SetWebhookHeadersParams ) -> WebhookSubscription :
61+ """Replace all custom headers. None or an empty dict clears them."""
62+ result = self ._post_result (
63+ "/admin/webhook.setHeaders" ,
64+ "Failed to set webhook headers" ,
65+ params ,
66+ )
67+ return WebhookSubscription .model_validate (result ["webhook" ])
68+
69+ def set_header (self , params : SetWebhookHeaderParams ) -> WebhookSubscription :
70+ """Set one custom header; its name is matched case-insensitively."""
71+ result = self ._post_result (
72+ "/admin/webhook.setHeader" ,
73+ "Failed to set webhook header" ,
74+ params ,
75+ )
76+ return WebhookSubscription .model_validate (result ["webhook" ])
77+
78+ def delete_header (self , params : DeleteWebhookHeaderParams ) -> WebhookSubscription :
79+ """Remove one custom header; its name is matched case-insensitively."""
80+ result = self ._post_result (
81+ "/admin/webhook.deleteHeader" ,
82+ "Failed to delete webhook header" ,
83+ params ,
84+ )
85+ return WebhookSubscription .model_validate (result ["webhook" ])
86+
87+ def reveal_secret (self , params : RevealWebhookSecretParams ) -> WebhookSubscription :
88+ """Return the current signing secret without changing it."""
89+ result = self ._post_result (
90+ "/admin/webhook.revealSecret" ,
91+ "Failed to reveal webhook secret" ,
92+ params ,
93+ )
94+ return WebhookSubscription .model_validate (result ["webhook" ])
95+
96+ def rotate_secret (self , params : RotateWebhookSecretParams ) -> WebhookSubscription :
97+ """Replace the signing secret and return its new value."""
98+ result = self ._post_result (
99+ "/admin/webhook.rotateSecret" ,
100+ "Failed to rotate webhook secret" ,
101+ params ,
102+ )
103+ return WebhookSubscription .model_validate (result ["webhook" ])
104+
105+ def set_events (self , params : SetWebhookEventsParams ) -> WebhookSubscription :
106+ """Select event types or namespace wildcards; None selects all. Tests always deliver."""
107+ result = self ._post_result (
108+ "/admin/webhook.setEvents" ,
109+ "Failed to set webhook events" ,
110+ params ,
111+ )
112+ return WebhookSubscription .model_validate (result ["webhook" ])
113+
114+ def event_types (self ) -> list [str ]:
115+ """Return selectable event types in the server's order.
116+
117+ The catalog excludes webhook.test, which is always delivered.
118+ """
119+ result = self ._post_result ("/admin/webhook.eventTypes" , "Failed to get webhook event types" )
120+ event_types : list [str ] = result ["eventTypes" ]
121+ return event_types
122+
43123 def delete (self , params : DeleteWebhookParams ) -> None :
44124 self ._post_void ("/admin/webhook.delete" , "Failed to delete webhook" , params )
45125
0 commit comments