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.
- Register for a (free) SuperSaaS account, and
- get your account name and API key on the Account Info page.
PHP 5.4 or greater.
No external libraries. Only the native json_encode
/json_decode
and stream_context_create
standard calls are used.
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:0.9.*"
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.
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;
...
Details of the data structures, parameters, and values can be found on the developer documentation site:
https://www.supersaas.com/info/dev
Get all account schedules:
SuperSaaS\Client::Instance()->schedules->list(); //=> array(Schedule, ...)
Get all services/resources by schedule_id
:
SuperSaaS\Client::Instance()->schedules->resources(12345); //=> array(Resource, ...)
Note: does not work for capacity type schedules.
Create a user with user attributes params:
SuperSaaS\Client::Instance()->users->create(array('full_name' => 'Example Name', 'email' => '[email protected]')); //=> User
Update a user by user_id
with user attributes params:
SuperSaaS\Client::Instance()->users->update(12345, array('full_name' => 'New Name')); //=> array()
Delete a single user by user_id
:
SuperSaaS\Client::Instance()->users->delete(12345); //=> array()
Get a single user by user_id
:
SuperSaaS\Client::Instance()->users->get(12345); //=> User
Get all users with optional form
and limit
/offset
pagination params:
SuperSaaS\Client::Instance()->users->list(date('Y-m-d H:i:s'), 25, 0); //=> array(User, ...)
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' => '[email protected]', 'slot_id' => 12345), true, true); //=> Appointment
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 a single appointment by schedule_id
and appointment_id
:
SuperSaaS\Client::Instance()->appointments->delete(12345, 67890); //=> array()
Get a single appointment by schedule_id
and appointment_id
:
SuperSaaS\Client::Instance()->appointments->get(12345, 67890); //=> Appointment
Get agenda (upcoming) appointments by schedule_id
and user_id
, with form
and slot
view params:
SuperSaaS\Client::Instance()->appointments->list(12345, 67890, true, true); //=> array(Appointment, ...)
Get agenda (upcoming) appointments by schedule_id
and user_id
, with form
and slot
view params:
SuperSaaS\Client::Instance()->appointments->agenda(12345, 67890, true, true); //=> array(Appointment, ...)
Get available appointments by schedule_id
, with from
time and length_minutes
and resource
params:
SuperSaaS\Client::Instance()->appointments->available(12345, '2018-1-31 00:00:00', 15, 'My Class'); //=> array(Appointment, ...)
Get recently changed appointments by schedule_id
, with from_time
view param:
SuperSaaS\Client::Instance()->appointments->changes(12345, '2018-1-31 00:00:00', true); //=> array(Appointment, ...)
Get recently changed appointment slots by schedule_id
, with from_time
view param:
SuperSaaS\Client::Instance()->appointments->changes(12345, '2018-1-31 00:00:00', true); //=> array(Slot, ...)
Get all forms by template superform_id
, with from
time param:
SuperSaaS\Client::Instance()->forms->list(12345, '2018-1-31 00:00:00'); //=> array(Form, ...)
Get a single form by form_id
:
SuperSaaS\Client::Instance()->forms->get(12345); //=> Form
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
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;
- SuperSaaS Registration
- Product Documentation
- Developer Documentation
- Python API Client
- Ruby API Client
- NodeJS API Client
- C# API Client
- Objective-C API Client
- Go API Client
Contact: [email protected]
The package follows semantic versioning, i.e. MAJOR.MINOR.PATCH
The SuperSaaS PHP API Client is available under the MIT license. See the LICENSE file for more info.