Class WebhooksClient
- Namespace
- GenerativeAI.Clients
- Assembly
- GenerativeAI.dll
A client for the Gemini Webhooks API (/webhooks): register endpoints that receive event notifications
for batch jobs, interactions and video generation instead of polling, ping them and rotate their signing secrets.
public class WebhooksClient : BaseClient
- Inheritance
-
WebhooksClient
- Inherited Members
- Extension Methods
Remarks
The wire format follows python-genai's generated webhooks client (snake_case field and query parameter names).
Requests go to {base}/{version}/webhooks on the Gemini Developer API and to
{base}/{version}/projects/{project}/locations/{location}/webhooks on Vertex AI.
Constructors
WebhooksClient(IPlatformAdapter, HttpClient?, ILogger?)
Initializes a new instance of the WebhooksClient class.
public WebhooksClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)
Parameters
platformIPlatformAdapterThe platform adapter (Google AI or Vertex AI).
httpClientHttpClientOptional HTTP client.
loggerILoggerOptional logger.
Methods
CreateAsync(CreateWebhookRequest, CancellationToken)
Creates a new webhook (POST /webhooks).
public Task<Webhook> CreateAsync(CreateWebhookRequest request, CancellationToken cancellationToken = default)
Parameters
requestCreateWebhookRequestThe webhook definition; Uri and SubscribedEvents are required.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<Webhook>
The created webhook. NewSigningSecret is only populated in this response.
CreateAsync(string, IEnumerable<string>, string?, CancellationToken)
Creates a new webhook (POST /webhooks).
public Task<Webhook> CreateAsync(string uri, IEnumerable<string> subscribedEvents, string? name = null, CancellationToken cancellationToken = default)
Parameters
uristringThe URI to which webhook events will be sent.
subscribedEventsIEnumerable<string>The events to subscribe to (see WebhookEvents).
namestringOptional user-provided name of the webhook.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<Webhook>
The created webhook. NewSigningSecret is only populated in this response.
DeleteAsync(string, CancellationToken)
Deletes a webhook (DELETE /webhooks/{id}).
public Task DeleteAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe webhook ID (a
webhooks/prefix is accepted).cancellationTokenCancellationTokenA cancellation token.
Returns
- Task
A task that completes when the webhook has been deleted.
GetAsync(string, CancellationToken)
Gets a webhook (GET /webhooks/{id}).
public Task<Webhook> GetAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe webhook ID (a
webhooks/prefix is accepted).cancellationTokenCancellationTokenA cancellation token.
Returns
GetWebhooksUrl()
Gets the URL of the webhooks collection.
protected string GetWebhooksUrl()
Returns
- string
The collection URL.
ListAllAsync(int?, CancellationToken)
Enumerates all webhooks, fetching subsequent pages as needed.
public IAsyncEnumerable<Webhook> ListAllAsync(int? pageSize = null, CancellationToken cancellationToken = default)
Parameters
pageSizeint?Optional page size used for each request.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<Webhook>
An async sequence of every webhook.
ListAsync(int?, string?, CancellationToken)
Lists webhooks, one page at a time (GET /webhooks).
public Task<WebhookListResponse> ListAsync(int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)
Parameters
pageSizeint?The maximum number of webhooks to return (the service defaults to 50, max 1000).
pageTokenstringA NextPageToken from a previous call.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<WebhookListResponse>
One page of webhooks.
PingAsync(string, CancellationToken)
Sends a ping event to a webhook (POST /webhooks/{id}:ping), e.g. to test the endpoint.
public Task<WebhookPingResponse> PingAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe webhook ID (a
webhooks/prefix is accepted).cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<WebhookPingResponse>
The (currently empty) ping response.
RotateSigningSecretAsync(string, string?, CancellationToken)
Generates a new signing secret for a webhook (POST /webhooks/{id}:rotateSigningSecret).
public Task<WebhookRotateSigningSecretResponse> RotateSigningSecretAsync(string id, string? revocationBehavior = null, CancellationToken cancellationToken = default)
Parameters
idstringThe webhook ID (a
webhooks/prefix is accepted).revocationBehaviorstringOptional revocation behavior for the previous signing secrets (see WebhookRevocationBehaviors).
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<WebhookRotateSigningSecretResponse>
The response holding the newly generated secret.
UpdateAsync(string, WebhookUpdate, string?, CancellationToken)
Updates a webhook (PATCH /webhooks/{id}).
public Task<Webhook> UpdateAsync(string id, WebhookUpdate update, string? updateMask = null, CancellationToken cancellationToken = default)
Parameters
idstringThe webhook ID (a
webhooks/prefix is accepted).updateWebhookUpdateThe fields to update; unset (
null) fields are not sent.updateMaskstringOptional comma-separated list of fields to update, sent as the
update_maskquery parameter (e.g."uri,subscribed_events").cancellationTokenCancellationTokenA cancellation token.