Webhooks API

API для работы с webhooks (уведомлениями о событиях).

Важно: Webhooks API требует OAuth-токен для аутентификации. Это API доступно только в рамках Partner API.

class aioyookassa.core.api.webhooks.WebhooksAPI(client: BaseAPIClient)[source]

Bases: BaseAPI[CreateWebhookParams, Webhook]

YooKassa webhooks API client.

Provides methods for creating, retrieving, and deleting webhooks. Webhooks API requires OAuth token for authentication.

Initialize base API client.

Parameters:

client – Base API client instance.

async create_webhook(params: CreateWebhookParams, oauth_token: str) Webhook[source]

Create a new webhook in YooKassa.

Parameters:
  • params (CreateWebhookParams) – Webhook creation parameters (CreateWebhookParams).

  • oauth_token (str) – OAuth token for authentication.

Returns:

Webhook object.

Return type:

Webhook

Seealso:

https://yookassa.ru/developers/api#create_webhook

async get_webhooks(oauth_token: str) WebhooksList[source]

Retrieve a list of webhooks for the OAuth token.

Parameters:

oauth_token (str) – OAuth token for authentication.

Returns:

WebhooksList object.

Return type:

WebhooksList

Seealso:

https://yookassa.ru/developers/api#list_webhooks

async delete_webhook(webhook_id: str, oauth_token: str) None[source]

Delete a webhook by its ID.

Parameters:
  • webhook_id (str) – Webhook identifier.

  • oauth_token (str) – OAuth token for authentication.

Seealso:

https://yookassa.ru/developers/api#delete_webhook

Методы

create_webhook

Создание нового webhook для подписки на события.

from aioyookassa.types.params import CreateWebhookParams
from aioyookassa.types.enum import WebhookEvent

params = CreateWebhookParams(
    event=WebhookEvent.PAYMENT_SUCCEEDED,
    url="https://example.com/webhook"
)
webhook = await client.webhooks.create_webhook(
    params=params,
    oauth_token="your_oauth_token"
)

# Доступные события:
# - WebhookEvent.PAYMENT_WAITING_FOR_CAPTURE
# - WebhookEvent.PAYMENT_SUCCEEDED
# - WebhookEvent.PAYMENT_CANCELED
# - WebhookEvent.PAYMENT_METHOD_ACTIVE
# - WebhookEvent.REFUND_SUCCEEDED
# - WebhookEvent.PAYOUT_SUCCEEDED
# - WebhookEvent.PAYOUT_CANCELED
# - WebhookEvent.DEAL_CLOSED

get_webhooks

Получение списка всех webhooks для OAuth-токена.

webhooks = await client.webhooks.get_webhooks(oauth_token="your_oauth_token")

if webhooks.list:
    for webhook in webhooks.list:
        print(f"Webhook {webhook.id}: {webhook.event} -> {webhook.url}")

delete_webhook

Удаление webhook.

await client.webhooks.delete_webhook(
    webhook_id="webhook_id",
    oauth_token="your_oauth_token"
)