When important changes occur on your Chargebee site, they are recorded as events. An event contains data about the affected resources and metadata, such as the timestamp of the change. For example, when a subscription is canceled due to non-payment, an event such as subscription_cancelled is recorded.
If webhooks are configured in Chargebee, events trigger those webhooks. If multiple webhooks are configured, Chargebee calls each webhook sequentially for every event. If a webhook call fails or times out, it is retried based on a fixed schedule. The webhook call is an HTTP POST with the content type application/json.
Caution: Webhooks are asynchronous and are not recommended for time-critical applications. Webhooks may arrive out of order or be delivered multiple times. For time-sensitive use cases, use the List events API to poll Chargebee for events.
To mark a webhook notification successful, the webhook must return an HTTP status code in the 2XX range. If a 2XX response is not received, Chargebee retries the webhook call with increasing delays for up to 2 days. You can also resend webhook calls manually from the web console.
Due to webhook retries, it is possible that your application receives the same webhook more than once. Detect such duplicates within your application to ensure the idempotency of the webhook call. This can be done by examining the id parameter since its value uniquely identifies an event.
For example, your application can do the following for each webhook notification:
id and keep it in a persistent store such as a relational database or redis.id is already processed.Webhooks can also arrive at your application out-of-order. This can be due to issues such as network delays or webhook failures. However, you can order the events by examining the resource_version attribute of the resource sent by the webhook. For every change made to the resource, resource_version is updated with a new timestamp in milliseconds.
For example, if you wish to sync resource changes from Chargebee to your application, you can:
rv1 of the resource_version attribute from the resource in the webhook.rv2 of resource_version from the resource stored on your side.rv1 > rv2, process the resource; otherwise, ignore.API Version
Chargebee supports multiple API versions now. The api_version attribute indicates the API version based on which the event content is structured. While processing webhooks, ensure that api_version is the same as the API version used by your webhook server's client library.
You can have basic authentication for the webhook URL.
In addition to securing your webhook, you can ensure the integrity of the event data by fetching it again using the Retrieve an Event API call.
Webhooks from Chargebee originate from a specific set of IP addresses.
{
"event": {
"id": "ev_16BPgETyVrQbiGhA",
"occurred_at": 1702645601,
"source": "admin_console",
"user": "sarah@sarah.com",
"object": "event",
"api_version": "v2",
"content": {
"subscription": {
"id": "16BPgETyVrQVHGh1",
"billing_period": 1,
"billing_period_unit": "month",
"customer_id": "sarah",
"status": "active",
"current_term_start": 1702578600,
"current_term_end": 1705256999,
"next_billing_at": 1705257000,
"created_at": 1702645601,
"started_at": 1702578600,
"activated_at": 1702578600,
"created_from_ip": "10.0.0.1",
"updated_at": 1702645601,
"has_scheduled_changes": false,
"channel": "web",
"resource_version": 1702645601793,
"deleted": false,
"object": "subscription",
"currency_code": "INR",
"subscription_items": [
{
"item_price_id": "cross-train-advanced-INR-1_MONTH",
"item_type": "plan",
"quantity": 1,
"quantity_in_decimal": "1.0000",
"unit_price": 11667,
"unit_price_in_decimal": "116.66667",
"amount": 11667,
"amount_in_decimal": "116.66667",
"free_quantity": 0,
"free_quantity_in_decimal": "0.0000",
"object": "subscription_item"
}
],
"due_invoices_count": 0,
"mrr": 0,
"has_scheduled_advance_invoices": false,
"override_relationship": false,
"create_pending_invoices": false,
"auto_close_invoices": true,
"business_entity_id": "16CQtCTrgrYwi9n2E"
},
"customer": {
"id": "sarah",
"auto_collection": "on",
"net_term_days": 0,
"allow_direct_debit": false,
"created_at": 1700038561,
"created_from_ip": "10.0.0.2",
"taxability": "taxable",
"updated_at": 1702645580,
"pii_cleared": "active",
"channel": "web",
"resource_version": 1702645580741,
"deleted": false,
"object": "customer",
"card_status": "valid",
"promotional_credits": 0,
"refundable_credits": 0,
"excess_payments": 0,
"unbilled_charges": 0,
"preferred_currency_code": "INR",
"mrr": 0,
"primary_payment_source_id": "pm_169vujTyVrL5fFDl",
"payment_method": {
"object": "payment_method",
"type": "card",
"reference_id": "tok_169vujTyVrL5LFDk",
"gateway": "chargebee",
"gateway_account_id": "gw_1mk51R4QrLmQtYMht",
"status": "valid"
},
"business_entity_id": "16CQtCTrgrYwi9n2E",
"tax_providers_fields": [],
"auto_close_invoices": true
},
"card": {
"status": "valid",
"gateway": "chargebee",
"gateway_account_id": "gw_1mk51R4QrLmQtYMht",
"iin": "411111",
"last4": "1111",
"card_type": "visa",
"funding_type": "credit",
"expiry_month": 12,
"expiry_year": 2024,
"created_at": 1702645580,
"updated_at": 1702645580,
"ip_address": "10.0.0.1",
"resource_version": 1702645580740,
"object": "card",
"masked_number": "************1111",
"customer_id": "boom",
"payment_source_id": "pm_169vujTyVrL5fFDl"
},
"invoice": {
"id": "203",
"customer_id": "boom",
"subscription_id": "16BPgETyVrQVHGh1",
"recurring": true,
"status": "paid",
"price_type": "tax_exclusive",
"date": 1702578600,
"due_date": 1702578600,
"net_term_days": 0,
"exchange_rate": 83.283543,
"total": 11667,
"amount_paid": 11667,
"amount_adjusted": 0,
"write_off_amount": 0,
"credits_applied": 0,
"amount_due": 0,
"paid_at": 1702645601,
"updated_at": 1702645601,
"resource_version": 1702645601783,
"deleted": false,
"object": "invoice",
"first_invoice": true,
"amount_to_collect": 0,
"round_off_amount": 0,
"new_sales_amount": 11667,
"has_advance_charges": false,
"currency_code": "INR",
"base_currency_code": "USD",
"generated_at": 1702578600,
"is_gifted": false,
"term_finalized": true,
"channel": "web",
"tax": 0,
"line_items": [
{
"id": "li_16BPgETyVrQWBGh3",
"date_from": 1702578600,
"date_to": 1705256999,
"unit_amount": 11667,
"quantity": 1,
"amount": 11667,
"pricing_model": "per_unit",
"is_taxed": false,
"tax_amount": 0,
"unit_amount_in_decimal": "116.66667",
"quantity_in_decimal": "1.0000",
"amount_in_decimal": "116.66667",
"object": "line_item",
"subscription_id": "16BPgETyVrQVHGh1",
"customer_id": "boom",
"description": "cross-train-advanced-INR-1_MONTH",
"entity_type": "plan_item_price",
"entity_id": "cross-train-advanced-INR-1_MONTH",
"metered": false,
"tax_exempt_reason": "export",
"discount_amount": 0,
"item_level_discount_amount": 0
}
],
"sub_total": 11667,
"linked_payments": [
{
"txn_id": "txn_16BPgETyVrQXVGh4",
"applied_amount": 11667,
"applied_at": 1702645601,
"txn_status": "success",
"txn_date": 1702645601,
"txn_amount": 11667
}
],
"applied_credits": [],
"adjustment_credit_notes": [],
"issued_credit_notes": [],
"linked_orders": [],
"dunning_attempts": [],
"notes": [
{
"note": "You can pay card."
}
],
"business_entity_id": "16CQtCTrgrYwi9n2E"
}
},
"event_type": "subscription_created",
"webhook_status": "not_configured",
"webhooks": [
{
"id": "whv2_Azz5aITsMVdKtVWV",
"webhook_status": "not_applicable",
"object": "webhook"
},
{
"id": "whv2_Azz5aITsMVaqCVT4",
"webhook_status": "not_applicable",
"object": "webhook"
},
{
"id": "whv2_169lhWTpiH34m3Vp8",
"webhook_status": "not_applicable",
"object": "webhook"
},
{
"id": "whv2_AzZiyPTsMVf4DUdv",
"webhook_status": "re_scheduled",
"object": "webhook"
}
]
}
}The email address of the user, if captured, in the API operation that triggered the event. This email address is captured through either the chargebee-request-origin-user or chargebee-request-origin-user-encoded custom HTTP request headers.
Applicable only when event_source is api.
webhook object data is a queued operation and hence there can be an additional delay of up to 5 seconds.This is a list of the event types we currently support. We will continue to add more events moving forward. All events follow a uniform pattern - <resource>_<event_name>. The resources that will be present in the event content are provided beneath each event type's description.
Note: If consolidated invoicing is enabled, the attributes invoice.subscription_id and credit_note.subscription_id should not be used (as it will not be present if the invoice / credit note has lines from multiple subscriptions). Instead to know the related subscriptions, their line_items' subscription_id attribute should be referred.
Retrieves list of events.
Retrieves a specific event identified by a unique event identifier.
Note: Only events that are less than 90 days old will be retrieved.