I am making a medical appointment booking application and using calendly for bookings. I am able to save scheduled event for the first time into db through js event successfully but not able to capture re-schedule event.
function isCalendlyEvent(e) {
return e.data.event && e.data.event.indexOf('calendly') === 0;
};
window.addEventListener(
'message',
function(e) {
if (isCalendlyEvent(e)) {
console.log(e.data);
}
}
);
I am able to capture scheduled event through "calendly.event_scheduled" event but not able to capture re-schedule event data.
Hello its a very irritating issue of calendly and there is no official solution provided for this. There is no such listener that captures the reschedule event.
There are possibly two work arounds:
Use webhooks, when reschedule event hits it fires cancelled and created hooks.
The solution that works for me is, to create a new event and delete the previous one through calendly api and you can get the delete api in the network tab by cancelling an event through the iframe. Following is my implementation in laravel after listening the create event through js call and ajax request to your controller and delete the previous event from calendly and in you db if you are saving in you db:
$scheduleDelete = ScheduledCall::where('id', $request->scheduleId)->first();
$cancelUrl = $scheduleDelete->calendly_cancel_url;
$cancelUrl = substr($cancelUrl, strrpos($cancelUrl, '/') + 1);
$cancelUrl = 'https://calendly.com/api/booking/cancellations/' . $cancelUrl;
$data = [
'cancellation' => [
'cancel_reason' => '',
'canceled_by' => 'Nonsulin'
]
];
$payload = json_encode($data);
Helper::apiCurlRequest($cancelUrl, 'PUT', config('app.CALENDLY_API_KEY'), $payload);
$scheduleDelete->delete();