Hey there, fellow developer! Ready to supercharge your scheduling game? Let's dive into the world of Cal.com API integration using the nifty @calcom/sdk
package. Trust me, it's easier than you might think!
Before we jump in, make sure you've got:
Alright, let's get our hands dirty:
mkdir calcom-integration && cd calcom-integration npm init -y npm install @calcom/sdk
Easy peasy, right?
Now, let's get that SDK up and running:
import Cal from "@calcom/sdk"; const cal = new Cal({ apiKey: "your-api-key-here" });
Boom! You're authenticated and ready to roll.
Let's start with some basics:
// Fetch user info const user = await cal.users.me(); // List event types const eventTypes = await cal.eventTypes.list();
See? It's like talking to an old friend.
Time to play with bookings:
// Create a booking const newBooking = await cal.bookings.create({ eventTypeId: 123, start: "2023-06-01T09:00:00Z", end: "2023-06-01T10:00:00Z", name: "John Doe", email: "[email protected]" }); // Update a booking await cal.bookings.update(newBooking.id, { name: "Jane Doe" }); // Cancel a booking await cal.bookings.cancel(newBooking.id);
You're basically a booking wizard now!
Let's peek at those schedules:
// Fetch availability const availability = await cal.availability.list(); // Update availability await cal.availability.update({ // Your availability update object here });
Webhooks are your friends. Treat them well:
// Set up a simple webhook endpoint app.post('/webhook', (req, res) => { const event = req.body; // Handle the event console.log('Received event:', event); res.sendStatus(200); });
Remember, even the best of us hit snags sometimes. Wrap your API calls in try-catch blocks and keep an eye on those rate limits. The Cal.com API is pretty chill, but it's always good to play nice.
Once you've got the basics down, sky's the limit! Integrate with your favorite CRM, automate follow-up emails, or build a fancy dashboard. The world is your oyster!
And there you have it! You're now armed and dangerous with Cal.com API knowledge. Go forth and schedule like a boss! If you want to dive deeper, check out the Cal.com API docs. Happy coding!