Hey there, fellow developer! Ready to dive into the world of Acuity Scheduling API integration? Let's get cracking!
Acuity Scheduling's API is a powerhouse for managing appointments programmatically. Whether you're looking to automate bookings, sync calendars, or create a custom scheduling flow, this guide will set you on the right path.
Before we jump in, make sure you've got:
First things first, let's get our project off the ground:
mkdir acuity-integration cd acuity-integration npm init -y npm install axios dotenv
Alright, time to get those API keys:
API
in the left sidebarUser ID
and API Key
Now, create a .env
file:
ACUITY_USER_ID=your_user_id
ACUITY_API_KEY=your_api_key
Let's set up our basic request structure:
require('dotenv').config(); const axios = require('axios'); const acuityClient = axios.create({ baseURL: 'https://acuityscheduling.com/api/v1/', auth: { username: process.env.ACUITY_USER_ID, password: process.env.ACUITY_API_KEY } });
async function getAppointmentTypes() { try { const response = await acuityClient.get('appointment-types'); return response.data; } catch (error) { console.error('Error fetching appointment types:', error); } }
async function getAvailability(date) { try { const response = await acuityClient.get('availability/times', { params: { date, appointmentTypeID: 1 } // Replace 1 with your actual appointment type ID }); return response.data; } catch (error) { console.error('Error fetching availability:', error); } }
async function bookAppointment(appointmentData) { try { const response = await acuityClient.post('appointments', appointmentData); return response.data; } catch (error) { console.error('Error booking appointment:', error); } }
Want to stay in the loop? Set up a webhook:
const express = require('express'); const app = express(); app.post('/webhook', express.json(), (req, res) => { const event = req.body; console.log('Received webhook event:', event); // Handle the event res.sendStatus(200); }); app.listen(3000, () => console.log('Webhook server running on port 3000'));
Remember to:
Don't forget to test! Here's a quick example using Jest:
test('fetches appointment types', async () => { const types = await getAppointmentTypes(); expect(types).toBeDefined(); expect(Array.isArray(types)).toBe(true); });
And there you have it! You're now equipped to integrate Acuity Scheduling into your JavaScript projects. Remember, this is just scratching the surface - there's a whole world of possibilities with the Acuity API. Happy coding, and may your calendars always be in sync!
For more details, check out the official Acuity API docs. Now go forth and schedule like a pro!