Docs

Log in to read the version of docs relevant to your site, or use the dropdown versions

How do I get the subscription id from web-hooks during cancel subscription.

Once you've configured your webhook URL (Settings (Configure Chargebee) >> Webhooks >> ), events will be posted back based on the event type. The event data will be posted as request body with content type set as application/JSON.

Sample code snippets to get subscription/customer details from the RAW POST DATA:

PHP:

$webhook_request = file_get_contents('php://input'); $event = ChargeBee_Event::deserialize($webhook_request); $eventType = $event->eventType;  // to get the event type $content = $event->content(); $subscription_id = $content->subscription()->id;   //get subscription ID $customer_email = $content->customer()->email;   // get customer email ID

JAVA:

BufferedReader reader = request.getReader(); Event event = new Event(reader); EventType eventType = event.eventType();   // to get the event type Event.Content content = event.content(); String subscriptionId = content.subscription().id();  //get subscription ID String customerEmail = content.customer().email();    // get customer email ID

Ruby:

event =  ChargeBee::Event.deserialize(request.body.string) event_type = event.event_type   // to get the event type content = event.content subscription_id = content.subscription.id  //get subscription ID customer_email = content.customer.email    // get customer email ID

.NET:

Event events = new Event(Request.InputStream); EventTypeEnum eventType = (EventTypeEnum)events.EventType;  // to get the event type Event.EventContent content = events.Content; String subscriptionId = content.Subscription.Id;  //get subscription ID String customerEmail = content.Customer.Email;     // get customer email ID

Make sure you do basic authentication for the webhook URL. More details here.

Was this article helpful?