Skip to content

Latest commit

 

History

History
355 lines (265 loc) · 10.4 KB

webhook-subscriptions.md

File metadata and controls

355 lines (265 loc) · 10.4 KB

Webhook Subscriptions

IWebhookSubscriptionsApi webhookSubscriptionsApi = client.WebhookSubscriptionsApi;

Class Name

WebhookSubscriptionsApi

Methods

List Webhook Event Types

Lists all webhook event types that can be subscribed to.

ListWebhookEventTypesAsync(
    string apiVersion = null)

Parameters

Parameter Type Tags Description
apiVersion string Query, Optional The API version for which to list event types. Setting this field overrides the default version used by the application.

Response Type

Task<Models.ListWebhookEventTypesResponse>

Example Usage

try
{
    ListWebhookEventTypesResponse result = await webhookSubscriptionsApi.ListWebhookEventTypesAsync();
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}

List Webhook Subscriptions

Lists all webhook subscriptions owned by your application.

ListWebhookSubscriptionsAsync(
    string cursor = null,
    bool? includeDisabled = false,
    string sortOrder = null,
    int? limit = null)

Parameters

Parameter Type Tags Description
cursor string Query, Optional A pagination cursor returned by a previous call to this endpoint.
Provide this to retrieve the next set of results for your original query.

For more information, see Pagination.
includeDisabled bool? Query, Optional Includes disabled Subscriptions.
By default, all enabled Subscriptions are returned.
Default: false
sortOrder string Query, Optional Sorts the returned list by when the Subscription was created with the specified order.
This field defaults to ASC.
limit int? Query, Optional The maximum number of results to be returned in a single page.
It is possible to receive fewer results than the specified limit on a given page.
The default value of 100 is also the maximum allowed value.

Default: 100

Response Type

Task<Models.ListWebhookSubscriptionsResponse>

Example Usage

bool? includeDisabled = false;
try
{
    ListWebhookSubscriptionsResponse result = await webhookSubscriptionsApi.ListWebhookSubscriptionsAsync(
        null,
        includeDisabled
    );
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}

Create Webhook Subscription

Creates a webhook subscription.

CreateWebhookSubscriptionAsync(
    Models.CreateWebhookSubscriptionRequest body)

Parameters

Parameter Type Tags Description
body CreateWebhookSubscriptionRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.CreateWebhookSubscriptionResponse>

Example Usage

CreateWebhookSubscriptionRequest body = new CreateWebhookSubscriptionRequest.Builder(
    new WebhookSubscription.Builder()
    .Name("Example Webhook Subscription")
    .EventTypes(
        new List<string>
        {
            "payment.created",
            "payment.updated",
        })
    .NotificationUrl("https://example-webhook-url.com")
    .ApiVersion("2021-12-15")
    .Build()
)
.IdempotencyKey("63f84c6c-2200-4c99-846c-2670a1311fbf")
.Build();

try
{
    CreateWebhookSubscriptionResponse result = await webhookSubscriptionsApi.CreateWebhookSubscriptionAsync(body);
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}

Delete Webhook Subscription

Deletes a webhook subscription.

DeleteWebhookSubscriptionAsync(
    string subscriptionId)

Parameters

Parameter Type Tags Description
subscriptionId string Template, Required [REQUIRED] The ID of the Subscription to delete.

Response Type

Task<Models.DeleteWebhookSubscriptionResponse>

Example Usage

string subscriptionId = "subscription_id0";
try
{
    DeleteWebhookSubscriptionResponse result = await webhookSubscriptionsApi.DeleteWebhookSubscriptionAsync(subscriptionId);
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}

Retrieve Webhook Subscription

Retrieves a webhook subscription identified by its ID.

RetrieveWebhookSubscriptionAsync(
    string subscriptionId)

Parameters

Parameter Type Tags Description
subscriptionId string Template, Required [REQUIRED] The ID of the Subscription to retrieve.

Response Type

Task<Models.RetrieveWebhookSubscriptionResponse>

Example Usage

string subscriptionId = "subscription_id0";
try
{
    RetrieveWebhookSubscriptionResponse result = await webhookSubscriptionsApi.RetrieveWebhookSubscriptionAsync(subscriptionId);
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}

Update Webhook Subscription

Updates a webhook subscription.

UpdateWebhookSubscriptionAsync(
    string subscriptionId,
    Models.UpdateWebhookSubscriptionRequest body)

Parameters

Parameter Type Tags Description
subscriptionId string Template, Required [REQUIRED] The ID of the Subscription to update.
body UpdateWebhookSubscriptionRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.UpdateWebhookSubscriptionResponse>

Example Usage

string subscriptionId = "subscription_id0";
UpdateWebhookSubscriptionRequest body = new UpdateWebhookSubscriptionRequest.Builder()
.Subscription(
    new WebhookSubscription.Builder()
    .Name("Updated Example Webhook Subscription")
    .Enabled(false)
    .Build())
.Build();

try
{
    UpdateWebhookSubscriptionResponse result = await webhookSubscriptionsApi.UpdateWebhookSubscriptionAsync(
        subscriptionId,
        body
    );
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}

Update Webhook Subscription Signature Key

Updates a webhook subscription by replacing the existing signature key with a new one.

UpdateWebhookSubscriptionSignatureKeyAsync(
    string subscriptionId,
    Models.UpdateWebhookSubscriptionSignatureKeyRequest body)

Parameters

Parameter Type Tags Description
subscriptionId string Template, Required [REQUIRED] The ID of the Subscription to update.
body UpdateWebhookSubscriptionSignatureKeyRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.UpdateWebhookSubscriptionSignatureKeyResponse>

Example Usage

string subscriptionId = "subscription_id0";
UpdateWebhookSubscriptionSignatureKeyRequest body = new UpdateWebhookSubscriptionSignatureKeyRequest.Builder()
.IdempotencyKey("ed80ae6b-0654-473b-bbab-a39aee89a60d")
.Build();

try
{
    UpdateWebhookSubscriptionSignatureKeyResponse result = await webhookSubscriptionsApi.UpdateWebhookSubscriptionSignatureKeyAsync(
        subscriptionId,
        body
    );
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}

Test Webhook Subscription

Tests a webhook subscription by sending a test event to the notification URL.

TestWebhookSubscriptionAsync(
    string subscriptionId,
    Models.TestWebhookSubscriptionRequest body)

Parameters

Parameter Type Tags Description
subscriptionId string Template, Required [REQUIRED] The ID of the Subscription to test.
body TestWebhookSubscriptionRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.TestWebhookSubscriptionResponse>

Example Usage

string subscriptionId = "subscription_id0";
TestWebhookSubscriptionRequest body = new TestWebhookSubscriptionRequest.Builder()
.EventType("payment.created")
.Build();

try
{
    TestWebhookSubscriptionResponse result = await webhookSubscriptionsApi.TestWebhookSubscriptionAsync(
        subscriptionId,
        body
    );
}
catch (ApiException e)
{
    // TODO: Handle exception here
    Console.WriteLine(e.Message);
}