PHP SDK
Availability and bookings from your PHP backend. Explicit scope, typed results and one send per mutation.
On this page
Install
PHP 8.2–8.5 with JSON and cURL, and Composer 2. Protected-file examples additionally require POSIX and ext-posix. Install through our hosted Composer repository. availkit/availkit is version 0.1.1. These are hosted releases; registry availability is not claimed.
composer init --name=example/availkit-integration --no-interaction
composer config repositories.availkit composer https://availkit.dev/downloads/composer.json
composer require availkit/availkit:0.1.1Configure your backend
A workspace credential belongs to one workspace and one test or live environment. The credential selects the actual environment on the server; the SDK’s environment value records your intended scope. Issue a matching key in the dashboard. Changing a client label cannot move data between environments.
For these booking examples grant Read and Book.
Other permissions
Catalog writes additionally need Edit catalog; customer/webhook administration needs Manage customers and webhooks. Linking a contact to a booking requires both Book and Manage customers and webhooks. Erasure and history pruning require Privacy plus customer management; expired-receipt pruning needs Privacy.
- In API keys, select your workspace and test, grant Read and Book, then create and download the secret shown once. Save the workspace and offering IDs separately.
- Move the downloaded key into a private directory outside source control. Substitute your actual file and IDs below; all YOUR_* values are placeholders.
mkdir -m 700 private
printf 'private/\n' >> .gitignore
mv ~/Downloads/YOUR_DOWNLOADED_KEY.key private/availkit-test.key
chmod 600 private/availkit-test.key
export AVAILKIT_WORKSPACE_ID=YOUR_WORKSPACE_ID
export AVAILKIT_OFFERING_ID=YOUR_TEST_OFFERING_ID
export AVAILKIT_ENVIRONMENT=test
export AVAILKIT_CREDENTIAL_FILE="$PWD/private/availkit-test.key"Keep workspace keys and webhook secrets on a trusted server. Never put them in browser bundles, mobile applications, client storage, public repositories, URLs or command arguments. A mobile app cannot keep a workspace secret private.
Save the following as inspect.php and run php inspect.php on your server.
<?php
require __DIR__ . '/vendor/autoload.php';
use AvailKit\{Client, Config, AvailKitException};
$client = new Client(Config::fromCredentialFile(
getenv('AVAILKIT_WORKSPACE_ID'),
getenv('AVAILKIT_ENVIRONMENT'),
getenv('AVAILKIT_CREDENTIAL_FILE')
));
echo 'Resources: ', count($client->listResources()->items), PHP_EOL;Create, read, move and cancel
First complete dashboard setup with a future opening window and a test offering. The installed package includes the runnable lifecycle example below. Each mutation saves an exclusive private intent file first and refuses an accidental rerun. Run each command once, in order, and inspect the confirmed result before continuing. No customer email is sent by this workspace example.
php vendor/availkit/availkit/examples/first-booking.php inspect
php vendor/availkit/availkit/examples/first-booking.php create
php vendor/availkit/availkit/examples/first-booking.php read
php vendor/availkit/availkit/examples/first-booking.php move
php vendor/availkit/availkit/examples/first-booking.php cancelOn failure, stop. Keep the private intent and use the example’s reconcile command for reads. Do not delete intent files to rerun a mutation. Learn the reconciliation rules.
Handle errors without leaking secrets
try {
$resources = $client->listResources();
} catch (AvailKitException $error) {
echo json_encode($error->jsonSerialize()), PHP_EOL;
// For an unknown mutation, keep its private intent and stop.
}Clients bound request/response sizes and the entire request with a configured deadline. Default workspace timeout is 10 seconds; the server has its own shorter admission/response budget. Redirects, cookies and automatic mutation retries are disabled. Transport or invalid-success responses can mean an unknown mutation outcome. Avoid logging exception traces, request objects, contact data or private intents.
Coverage and versioning
34 workspace operations and 7 public booking operations cover catalog, weekly hours, offerings, availability, bookings, customers, webhooks, events, usage, maintenance and page publication. Public clients accept page IDs and per-booking capabilities separately. Account enrollment, passkeys, sessions and key issuance use the dashboard, not these SDKs.
Request/response types retain API field names. PHP uses immutable response DTOs and documented request array shapes. The package includes its operation coverage manifest, README, examples and license. Authority matrix.
During 0.x, minor versions may introduce documented breaking changes; patch versions preserve documented behavior. Pin the exact version for production and review release notes before upgrading. Supported runtimes are tested at release; runtimes outside that range are not claimed.
Keep mutation outcomes intact
Before sending a mutation, retain its exact body, method, API origin, workspace/page, test/live scope, creation time, authority fingerprint and idempotency key where supported. Guest operations additionally retain the original booking capability and contact-reuse proof privately. Save on your server before the send; do not log secrets or put them in URLs.
- Not sent
- Local validation or preparation failed before a request. Correct the input; no network effect occurred.
- Rejected
- A recognized API rejection arrived. Handle its structured code; never infer every HTTP error proves no commit.
- Confirmed success
- A validated success response arrived. Preserve the receipt and booking ID.
- Unknown
- The response was lost, timed out, malformed or otherwise insufficient. The mutation may have committed. Stop and retain the original intent.
Read current state with the original authority. A current read can confirm what exists; it cannot reconstruct a missing acknowledgment or prove a booking never existed. Never generate a fresh key or a replacement request to recover an unknown result.
| Operation | Safe handling after an unknown outcome |
|---|---|
| Workspace or public booking create, move, cancel | Retain the original body and key. The server keeps booking receipts for 24 hours. Only an explicitly authorized, identical replay within that window and original scope/authority can use that receipt. A changed body conflicts. A new key means a new intent. |
| Catalog, hours, customers, webhooks, booking-page settings and maintenance | These do not share booking replay receipts. Inspect current state and reconcile manually. Secret issuance has no secret recovery; listing cannot reveal the secret again. |
| Account/passkey/session ceremonies | Use the same-origin dashboard and the specific ceremony’s continuation rules; backend SDKs do not automate them. Use the dashboard’s Account & security controls for supported recovery; keep a spare passkey and offline recovery codes. |