Booking through the API lets you take advantage of Acuity's powerful scheduling platform while creating a more integrated scheduling interface or more automated booking process. And it's as easy as 1-2-3:
- Set up Acuity's PHP SDK
- Fetch available times for a service
- Schedule the appointment
Once we've set up the SDK, we'll use a number of Acuity's APIs to fetch available times and schedule the appointment:
- get/appointment-types to get the ID for one of our services
- get/availability/dates and get/availability/times to find an available slot for an appointment
- post/appointments to schedule the appointment.
Setting up Acuity's PHP SDK is super simple using composer. Just run the composer require command:
$ composer require acuityscheduling/acuityscheduling
Then in your PHP script require the composer autoloader and create a new instance of
<?php require('./vendor/autoload.php'); $acuity = new AcuityScheduling(array( 'userId' => YOUR_USER_ID, 'apiKey' => 'YOUR_API_KEY' ));
If you're not using Composer, you can get our SDK directly from Github and then manually require
Before booking an appointment, we'll have to find an available time slot for it. Availability in Acuity can vary by calendar, date and even service (appointment type). At a minimum, we'll need the appointment type to find some available slots.
To find your available appointment types, make a request to `/appointment-types':
$types = $acuity->request('/appointment-types');
Once you have the ID of the service you'd like to fetch availability for, you can check which dates have some available slots using the
$dates = $acuity->request('/availability/dates', array( 'query' => array( 'month' => '2016-04', 'appointmentTypeID' => 5 ) ));
Finally, get the time slots for one of the available dates:
$times = $acuity->request('/availability/times', array( 'query' => array( 'date' => '2016-04-26', 'appointmentTypeID' => 5 ) ));
Once you have an available time slot, you'll be able to schedule an appointment. Creating an appointment has a few required client fields by default:
appointmentTypeID and the available
datetime time slot.
If your appointment type has any custom intake forms, you can set those as well using the
$appointment = $acuity->request('/appointments', array( 'method' => 'POST', 'data' => array( 'firstName' => 'Bob', 'lastName' => 'Burger', 'email' => '[email protected]', 'datetime' => '2016-04-26T19:00:00-0700', 'appointmentTypeID' => 5, 'fields' => array( array( 'id' => 4, // Field ID of my intake form address question 'value' => '1600 Pennsylvania Avenue' ) ) ) ));
That's it! Once a new appointment is in the system, we'll take care of the rest. Admin's can view it on the backend and we'll send out our automatic confirmation e-mails and perform any integrations such as Acuity's 2-way calendar syncing.