Discover how to integrate Lovable with Zocdoc using our step-by-step guide for seamless appointment scheduling and efficient patient management.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
In your Lovable project, create a new TypeScript file called zocdocIntegration.ts. This file will contain the functions required to communicate with Zocdoc’s API. You do not need a terminal to install node packages; instead, if your project does not include a fetch function natively, add a polyfill directly in your code (for example, by using a CDN or embedding a basic fetch function). For now, assume that fetch is available.
/ zocdocIntegration.ts /
// Replace with the actual Zocdoc API base URL and your API key.
const ZOCDOCAPIBASE_URL = 'https://api.zocdoc.com';
const ZOCDOCAPIKEY = 'YOURZOCDOCAPI_KEY'; // Insert your Zocdoc API key here
export interface ZocdocAppointment {
id: string;
date: string;
time: string;
provider: string;
patient: string;
}
export async function getAppointments(): Promise {
const url = ${ZOCDOC_API_BASE_URL}/appointments;
const response = await fetch(url, {
method: 'GET',
headers: {
'Authorization': Bearer ${ZOCDOC_API_KEY},
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error('Failed to fetch appointments from Zocdoc');
}
const data = await response.json();
return data.appointments as ZocdocAppointment[];
}
export async function createAppointment(appointment: ZocdocAppointment): Promise {
const url = ${ZOCDOC_API_BASE_URL}/appointments;
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': Bearer ${ZOCDOC_API_KEY},
'Content-Type': 'application/json'
},
body: JSON.stringify(appointment)
});
if (!response.ok) {
throw new Error('Failed to create appointment on Zocdoc');
}
const data = await response.json();
return data.appointment as ZocdocAppointment;
}
Create a new TypeScript file named zocdocRoutes.ts. This file will define endpoints that use the functions in zocdocIntegration.ts. Then later, you will integrate these routes into your main Lovable application code.
/ zocdocRoutes.ts /
import express from 'express';
import { getAppointments, createAppointment } from './zocdocIntegration';
const router = express.Router();
router.get('/zocdoc/appointments', async (req, res) => {
try {
const appointments = await getAppointments();
res.json(appointments);
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
router.post('/zocdoc/appointments', async (req, res) => {
try {
const appointmentData = req.body;
const appointment = await createAppointment(appointmentData);
res.json(appointment);
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
export default router;
Within your main application file (for example, app.ts or server.ts), import the zocdocRoutes and mount them on a desired path. This step integrates the Zocdoc API endpoints into your Lovable project.
/ In your main app file (e.g., app.ts) /
import express from 'express';
import bodyParser from 'body-parser';
import zocdocRoutes from './zocdocRoutes';
const app = express();
// Ensure request bodies are parsed as JSON.
app.use(bodyParser.json());
// Mount the Zocdoc routes under the /api path.
app.use('/api', zocdocRoutes);
// Listen on your configured port.
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(Server is running on port ${PORT});
});
Now that you have added the Zocdoc integration code, you can test the endpoints. In your Lovable project, when the server is running, the following endpoints should be available:
// GET appointments from Zocdoc
GET /api/zocdoc/appointments
// Create a new appointment in Zocdoc
POST /api/zocdoc/appointments
with appointment JSON in the request body
Ensure you replace 'YOURZOCDOCAPI_KEY' with the actual API key provided by Zocdoc and update the API URL if necessary.
By following these steps and inserting the code snippets into the appropriate files, you will have integrated your Lovable project with Zocdoc.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.