Real-time PHP Webhook System - Automatic keypad code management via Smoobu webhooks!
- ✅ Real-time sync - Webhooks trigger instant code creation/update/deletion
- ✅ SMS notifications - Guest receives PIN via SMS + admin notifications
- ✅ Email messages - Multilingual messages sent to guests (EN/DE/PL)
- ✅ Database logging - Complete audit trail of all operations
- ✅ Idempotency - Prevents duplicate processing
- ✅ Apartment changes - Handles booking moves between apartments
- ✅ Auto cleanup - Cancelled bookings removed immediately
Create MySQL database and tables:
CREATE DATABASE thekeys;
CREATE TABLE webhook_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
event_type VARCHAR(50),
booking_id INT,
payload JSON,
processed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE sync_history (
id INT AUTO_INCREMENT PRIMARY KEY,
booking_id INT,
code_id INT,
operation VARCHAR(20),
success BOOLEAN,
error_message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Copy the example config and fill in your details:
cp config.example.php config.phpEdit config.php with your credentials:
return [
'database' => [
'host' => 'localhost',
'database' => 'thekeys',
'username' => 'your_db_user',
'password' => 'your_db_password'
],
'thekeys' => [
'username' => '+33650868488',
'password' => 'your_password'
],
'smoobu' => [
'api_key' => 'your_smoobu_api_key'
],
'smsfactor' => [
'api_token' => 'your_sms_token',
'recipients' => ['+48503165434']
],
'apartment_locks' => [
'505200' => 3723 // Smoobu Apartment ID => Lock ID
],
'lock_accessoires' => [
3723 => 'OXe37UIa' // Lock ID => STRING accessoire ID
]
];Upload to your web server:
webhook.php- Main webhook endpointSmoobuWebhook.php- Event handlerTheKeysAPI.php- API clientconfig.php- Your configuration
- Login to Smoobu
- Go to Settings → API & Webhooks
- Add new webhook:
- URL:
https://your-domain.com/thekeys/webhook.php - Events: Reservation Created, Updated, Cancelled
- URL:
- Save
Smoobu Event → webhook.php
↓
1. Validate request
2. Log to database
3. Check idempotency
4. Process event:
- New → Create code + Send SMS + Send email
- Update → Update code + Send SMS
- Cancel → Delete code + Send SMS
5. Return 200 OK
Automatic SMS sent via SMSFactor to:
- Guest's phone (from booking) - Receives PIN code
- Admin phone(s) (from config) - Receives all notifications
Example SMS:
🔑 NEW BOOKING #125712
John Doe
Studio 1A
2026-01-29 → 2026-01-30
PIN: 184717
Multilingual email sent to guest with:
- Building entrance code
- Lobby door code
- Apartment door code (with PIN)
- Check-in/check-out times
- Parking information
- Contact phone
Languages supported: English, German, Polish
Authentication:
POST /api/login_check
List Codes:
GET /fr/api/v2/partage/all/serrure/{lock_id}?_format=json
Create Code:
POST /fr/api/v2/partage/create/{lock_id}/accessoire/{id_accessoire}
Update Code:
POST /fr/api/v2/partage/accessoire/update/{code_id}
Delete Code:
POST /fr/api/v2/partage/accessoire/delete/{code_id}
Send Message to Guest:
POST /api/reservations/{booking_id}/messages/send-message-to-guest
Send SMS:
POST /send
Authorization: Bearer {token}
id_accessoire (NOT numeric id)!
Correct:
"OXe37UIa"✅"f4H7DpX0"✅"FBptKZHE"✅
Wrong:
4413❌4383❌
Find STRING IDs by calling the LIST endpoint.
Lock ID:
- Login to https://app.the-keys.fr
- Go to locks list
- Click a lock
- URL shows:
/compte/serrure/{LOCK_ID}/view_partage
Accessoire STRING ID:
- Use TheKeysAPI to list codes
- Check
accessoire.id_accessoirefield - Use that STRING value
Smoobu Apartment ID:
- Login to Smoobu
- Go to apartments
- Click apartment
- Check URL or details
Smoobu API Key:
- Smoobu Settings → API
- Generate/copy key
SMSFactor API Token:
- Login to SMSFactor
- Go to API section
- Generate/copy token
SELECT * FROM webhook_logs
ORDER BY created_at DESC
LIMIT 10;SELECT * FROM sync_history
ORDER BY created_at DESC
LIMIT 10;SELECT operation, COUNT(*) as count
FROM sync_history
GROUP BY operation;thekeys/
├── webhook.php # Main webhook endpoint
├── SmoobuWebhook.php # Event handler
├── TheKeysAPI.php # The Keys API client
├── config.php # Configuration (gitignored)
├── config.example.php # Configuration template
├── README.md # This file
├── README_WEBHOOK.md # Webhook documentation
├── SECURITY.md # Security guidelines
├── .gitignore # Git ignore rules
└── logs/
└── webhook.log # Webhook logs
config.phpis gitignored (contains credentials)- Database logs all webhook requests (audit trail)
- Idempotency prevents duplicate processing
- Optional IP whitelist and webhook secret validation
See SECURITY.md for details.
- Check
logs/webhook.log - Query
webhook_logstable - Verify URL in Smoobu is correct
- Test with manual POST request
- Verify SMSFactor token in config
- Check logs for HTTP status codes
- Verify phone numbers are in international format
- Check The Keys credentials
- Verify apartment/lock mappings
- Ensure accessoire IDs are STRINGS
- Check
sync_historytable for errors
MIT
Check logs and database for detailed information:
- File:
logs/webhook.log - Database:
webhook_logsandsync_historytables
Real-time webhook system with SMS notifications! 🎉