PHP SDK for interacting with the LockMe API. This library provides a simple interface for authentication and making API calls to the LockMe platform.
For comprehensive API documentation, please visit https://apidoc.lock.me/.
- PHP 7.2 or higher
- ext-json
- Composer
You can install the package via composer:
composer require lustmored/lockme-sdkTo use the SDK, you need to create an instance with your client credentials:
use Lockme\SDK\Lockme;
$sdk = new Lockme([
"clientId" => 'YOUR_CLIENT_ID',
"clientSecret" => "YOUR_CLIENT_SECRET",
"redirectUri" => 'YOUR_REDIRECT_URI',
// Optional: Custom API domain (defaults to https://api.lock.me)
"apiDomain" => 'https://api.lock.me'
]);The SDK uses OAuth2 for authentication. Here's how to implement the authentication flow:
// Define the scopes you need - rooms_manage is required for booking operations
$authUrl = $sdk->getAuthorizationUrl(['rooms_manage']);
// Redirect the user to the authorization URL
header('Location: ' . $authUrl);
exit;// In your callback URL handler
$code = $_GET['code'];
$state = $_GET['state'];
try {
// Exchange the authorization code for an access token
$accessToken = $sdk->getTokenForCode($code, $state);
// Save the token for future use
file_put_contents('token.json', json_encode($accessToken));
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}try {
// Load the token from storage and set up automatic saving when refreshed
$sdk->loadAccessToken(
fn() => file_get_contents('token.json'),
fn($token) => file_put_contents('token.json', json_encode($token))
);
// Now you can make API calls
$rooms = $sdk->RoomList();
} catch(Exception $e) {
echo 'Error: ' . $e->getMessage();
}$result = $sdk->Test();$rooms = $sdk->RoomList();use DateTime;
$roomId = 123;
$date = new DateTime();
$reservations = $sdk->GetReservations($roomId, $date);$data = [
'date' => '2023-01-01', // Date in YYYY-MM-DD format
'hour' => '11:00:00', // Time in HH:MM:SS format
'roomid' => 123, // Room ID
'extid' => 'abc123', // External ID (your system's ID)
'name' => 'John', // Customer's first name
'surname' => 'Doe', // Customer's last name
'email' => 'john.doe@example.com', // Customer's email
'phone' => '+1234567890', // Customer's phone number
'people' => 4, // Number of people
'pricer' => 1, // Pricer ID (pricing option)
'comment' => 'Special requests', // Booking comment
'price' => 100.00, // Price
];
$reservationId = $sdk->AddReservation($data);$roomId = 123;
$reservationId = 'abc123';
$reservation = $sdk->Reservation($roomId, $reservationId);Note: Whenever a booking ID is used, you can also use an external ID (the one set via API) by using the format "ext/{id}". For example:
$reservationId = 'ext/abc123';
$roomId = 123;
$reservationId = 'abc123';
$data = [
'name' => 'John', // Customer's first name
'surname' => 'Doe', // Customer's last name
'email' => 'john.doe@example.com', // Customer's email
'phone' => '+1234567890', // Customer's phone number
'people' => 4, // Number of people
'pricer' => 1, // Pricer ID (pricing option)
'comment' => 'Updated requests', // Booking comment
'price' => 100.00, // Price
];
$result = $sdk->EditReservation($roomId, $reservationId, $data);$roomId = 123;
$reservationId = 'abc123';
$result = $sdk->DeleteReservation($roomId, $reservationId);$roomId = 123;
$date = new DateTime();
$settings = $sdk->GetDateSettings($roomId, $date);$roomId = 123;
$date = new DateTime();
$settings = [ // Specific hour settings
[
"hour" => "16:00:00", // Time slot
"pricers" => [1227], // Available pricing options for this slot
],
[
"hour" => "18:00:00",
"pricers" => [1227, 1228],
]
];
$result = $sdk->SetDateSettings($roomId, $date, $settings);getAuthorizationUrl(array $scopes): Get the authorization URL for OAuth2 flowgetTokenForCode(string $code, string $state): Exchange authorization code for access tokenrefreshToken(?AccessToken $accessToken): Refresh an access tokensetDefaultAccessToken($token): Set the default access token for API callsloadAccessToken(callable $load, ?callable $save): Load and optionally set up saving of access tokenTest(): Test the API connectionRoomList(): Get list of roomsReservation(int $roomId, string $id): Get booking detailsAddReservation(array $data): Create a new bookingDeleteReservation(int $roomId, string $id): Delete a bookingEditReservation(int $roomId, string $id, array $data): Edit a bookingMoveReservation(int $roomId, string $id, array $data): Move a bookingGetReservations(int $roomId, DateTime $date): Get bookings for a room on a specific dateGetMessage(int $messageId): Get a messageMarkMessageRead(int $messageId): Mark a message as readGetDateSettings(int $roomId, DateTime $date): Get settings for a specific dateSetDateSettings(int $roomId, DateTime $date, array $settings): Set settings for a specific dateRemoveDateSettings(int $roomId, DateTime $date): Remove custom settings for a specific dateGetDaySettings(int $roomId, int $day): Get settings for a specific day of the weekSetDaySettings(int $roomId, int $day, array $settings): Set settings for a specific day of the week
This package is licensed under the GPL-3.0-or-later License - see the LICENSE file for details.
- Jakub Caban (kuba@lock.me)