Hey there, fellow developer! Ready to supercharge your scheduling game? Let's dive into the world of Calendly API integration using PHP. We'll be leveraging the awesome lobrs/calendly-sdk-php
package to make our lives easier. Buckle up!
Before we jump in, make sure you've got:
First things first, let's get that SDK installed:
composer require lobrs/calendly-sdk-php
Easy peasy, right?
Now, let's initialize our Calendly client:
use Lobrs\Calendly\Client; $client = new Client('YOUR_API_TOKEN');
Just like that, we're ready to roll!
Let's start with some basic operations to get our feet wet:
$user = $client->users()->current(); echo $user->name; // "John Doe"
$eventTypes = $client->eventTypes()->list(); foreach ($eventTypes as $eventType) { echo $eventType->name . "\n"; }
$events = $client->events()->list(); foreach ($events as $event) { echo $event->name . " - " . $event->start_time . "\n"; }
Ready to level up? Let's tackle some advanced stuff:
$webhook = $client->webhooks()->create([ 'url' => 'https://your-webhook-url.com', 'events' => ['invitee.created', 'invitee.canceled'] ]);
$payload = json_decode(file_get_contents('php://input'), true); if ($payload['event'] === 'invitee.created') { // Handle new booking }
$client->events()->cancel('EVENT_UUID', [ 'reason' => 'Unexpected schedule conflict' ]);
Don't forget to handle those pesky errors and respect API limits:
try { // Your API calls here } catch (\Lobrs\Calendly\Exception\RateLimitException $e) { // Wait and retry } catch (\Lobrs\Calendly\Exception\CalendlyException $e) { // Handle other exceptions }
Let's put it all together:
$eventTypes = $client->eventTypes()->list(); foreach ($eventTypes as $eventType) { echo "<a href='book.php?type={$eventType->uri}'>{$eventType->name}</a><br>"; } // In book.php $availableTimes = $client->availableTimes()->list($_GET['type']); // Display available times and handle booking
Pro tip: Use Calendly's sandbox environment for testing. And don't forget to log everything – your future self will thank you!
And there you have it! You're now equipped to build some seriously cool scheduling features with Calendly's API. Remember, the official Calendly API docs are your best friend for more in-depth info.
Now go forth and schedule like a boss! 🚀