SuperSaaS PHP SDK
Online bookings/appointments/calendars in PHP using the SuperSaaS scheduling platform - https://supersaas.com
The SuperSaaS API provides services that can be used to add online booking and scheduling functionality to an existing website or CRM software.
Prerequisites
- Register for a (free) SuperSaaS account, and
- get your account name and API key on the Account Info page.
Dependencies
PHP 5.4 or greater.
No external libraries. Only the native json_encode
/json_decode
and stream_context_create
standard calls are used.
Installation
1: Composer
The SuperSaaS PHP API Client is available from Packagist and can be included in your project via composer. Note, the supersaas-api-client may update major versions with breaking changes, so it's recommended to use a major version when expressing the package dependency. e.g.
$ composer require "supersaas/api-client:1.1.*"
In composer.json
:
{
"require": {
"supersaas/supersaas-api-client": "^1"
}
}
2: Manual
Download or checkout the project from github, and include the src/SuperSaaS
folder manually.
Configuration
The Client
can be used either (1) through the singleton helper method Instance
, e.g.
SuperSaaS\Client::Instance(); //=> Client
And configured with authorization credentials using the configure
method:
SuperSaaS\Client::configure('accountname', 'apikey');
Or else by (2) simply creating a new client instance and setting the properties manually, e.g.
$client = new Supersaas\Client();
$client->account_name = 'accountname';
$client->api_key = 'apikey';
Note, ensure that
configure
is called beforeInstance
, otherwise the client will be initialized with configuration defaults.
If the client isn't configured explicitly, it will use default ENV
variables for the account name and api key.
Set these ENV
variables before calling the client.
putenv("SSS_API_ACCOUNT_NAME=your-env-supersaas-account-name");
putenv("SSS_API_KEY=your-env-supersaas-account-api-key");
SuperSaaS\Client::Instance()->account_name; //=> 'your-env-supersaas-account-name'
SuperSaaS\Client::Instance()->api_key; //=> 'your-env-supersaas-account-api-key'
All configuration options can be individually set on the client.
SuperSaaS\Client::Instance()->api_key = 'xxxxxxxxxxxxxxxxxxxxxx';
SuperSaaS\Client::Instance()->verbose = TRUE;
...
API Methods
Details of the data structures, parameters, and values can be found on the developer documentation site:
https://www.supersaas.com/info/dev
List Schedules
Get all account schedules:
SuperSaaS\Client::Instance()->schedules->getList(); //=> array(Schedule, ...)
List Resource
Get all services/resources by schedule_id
:
SuperSaaS\Client::Instance()->schedules->resources(12345); //=> array(Resource, ...)
Note: does not work for capacity type schedules.
Create User
Create a user with user attributes params:
SuperSaaS\Client::Instance()->users->create(array('name' => 'name@name.com', 'full_name' => 'Example Name', 'email' => 'example@example.com')); //=> User
Update User
Update a user by user_id
with user attributes params:
SuperSaaS\Client::Instance()->users->update(12345, array('full_name' => 'New Name')); //=> array()
Delete User
Delete a single user by user_id
:
SuperSaaS\Client::Instance()->users->delete(12345); //=> array()
Get User
Get a single user by user_id
:
SuperSaaS\Client::Instance()->users->get(12345); //=> User
List Users
Get all users with optional form
and limit
/offset
pagination params:
SuperSaaS\Client::Instance()->users->getList(true, 25, 0); //=> array(User, ...)
Create Appointment/Booking
Create an appointment by schedule_id
and user_id
with appointment attributes and form
and webhook
params:
SuperSaaS\Client::Instance()->appointments->create(12345, 67890, array('full_name' => 'Example Name', 'email' => 'example@example.com', 'slot_id' => 12345), TRUE, TRUE); //=> Appointment
Update Appointment/Booking
Update an appointment by schedule_id
and appointment_id
with appointment attributes params:
SuperSaaS\Client::Instance()->appointments->update(12345, 67890, array('full_name' => 'New Name')); //=> array()
Delete Appointment/Booking
Delete a single appointment by schedule_id
and appointment_id
:
SuperSaaS\Client::Instance()->appointments->delete(12345, 67890); //=> array()
Get Appointment/Booking
Get a single appointment by schedule_id
and appointment_id
:
SuperSaaS\Client::Instance()->appointments->get(12345, 67890); //=> Appointment
List Appointments/Bookings
Get agenda (upcoming) appointments by schedule_id
and user_id
, with form
and slot
view params:
SuperSaaS\Client::Instance()->appointments->getList(12345, 67890, TRUE, TRUE); //=> array(Appointment, ...)
Get Agenda
Get agenda (upcoming) appointments by schedule_id
and user_id
, with form
and slot
view params:
SuperSaaS\Client::Instance()->appointments->agenda(schedule_id=12345, user_id=67890, form=TRUE, slot=FALSE); //=> array(Appointment, ...)
SuperSaaS\Client::Instance()->appointments->agenda(schedule_id=12345, user_id=67890, form=TRUE, slot=TRUE); //=> array(Slot, ...)
Get Available Appointments/Bookings
Get available appointments by schedule_id
, with from
time and length_minutes
and resource
params:
SuperSaaS\Client::Instance()->appointments->available(schedule_id=12345, from='2018-01-31 00:00:00', length_minutes=15, resource='My Class'); //=> array(Appointment, ...)
Get Recent Changes
Get recently changed appointment slots by schedule_id
, with from_time
and slot
view param:
SuperSaaS\Client::Instance()->appointments->changes(schedule_id=12345, from_time='2018-01-31 00:00:00', slot=FALSE); //=> array(Appointment, ...)
SuperSaaS\Client::Instance()->appointments->changes(schedule_id=12345, from_time='2018-01-31 00:00:00', slot=TRUE); //=> array(Slot, ...)
Get list of appointments
Get list of appointments by schedule_id
, with today
, from time
, to
time and slot
view param:
SuperSaaS\Client::Instance()->appointments->listAppointments(schedule_id=12345, today=TRUE, from_time='2020-01-31 00:00:00',from_time='2020-02-01 00:00:00' slot=False)
List Template Forms
Get all forms by template superform_id
, with from
time param:
SuperSaaS\Client::Instance()->forms->getList(12345, '2018-01-31 00:00:00'); //=> array(Form, ...)
Get Form
Get a single form by form_id
:
SuperSaaS\Client::Instance()->forms->get(12345); //=> Form
Examples
The ./examples folder contains several executable PHP scripts demonstrating how to use the API Client for common requests.
The examples will require your account name, api key, and some of the examples a schedule id and/or user id and/or form id. These can be set as environment variables. e.g.
$ export SSS_API_UID=myuserid SSS_API_SCHEDULE=myscheduleid SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=myapikey && php -f ./examples/appointments.php
$ export SSS_API_FORM=myuserid SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=myapikey && php -f ./examples/forms.php
$ export SSS_API_ACCOUNT_NAME=myaccountname && export SSS_API_KEY=myapikey && php -f ./examples/users.php
Testing
The HTTP requests can be stubbed by configuring the client with the dry_run
option, e.g.
SuperSaaS\Client::Instance()->dry_run = TRUE;
Note, stubbed requests always return an empty array.
The Client
also provides a last_request
attribute containing the http array object from the last performed request, e.g.
SuperSaaS\Client::Instance()->last_request; //=> array('method' => ..., 'header' => ..., 'content' => ...)
The headers, body, etc. of the last request can be inspected for assertion in tests, or for troubleshooting failed API requests.
For additional troubleshooting, the client can be configured with the verbose
option, which will puts
any JSON contents in the request and response, e.g.
SuperSaaS\Client::Instance()->verbose = TRUE;
Run internal unit tests (phpunit)
./vendor/bin/phpunit # Runs all
./vendor/bin/phpunit --filter AppointmentsUnitTest # Run selection
Additional Information
- SuperSaaS Registration
- Product Documentation
- Developer Documentation
- Python API Client
- Ruby API Client
- NodeJS API Client
Contact: support@supersaas.com
Releases
The package follows semantic versioning, i.e. MAJOR.MINOR.PATCH
License
The SuperSaaS PHP API Client is available under the MIT license. See the LICENSE file for more info.