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

Modified on: Mon, 28 Jan, 2019 at 6:16 PM

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:



$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




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



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




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.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.