Webhooks
Mit Webhooks kann man über bestimmte Ereignisse in Propstack benachrichtigt werden, wie z.B. wenn ein Objekt aktualisiert wird.
Wenn ein Event ausgelöst wird, wird die URL unter target_url
mit einem POST
aufgerufen und die Daten des Kontaktes bzw. des Objektes mit übergeben.
Bei client_updated
und property_updated
wird zusätzlich der Parameter changed_attributes
übergeben, damit man auf Aktualisierungen von bestimmten Feldern reagieren kann. Beispielsweise will man in seiner eigenen App eine Aktion ausführen, sobald sich der Preis eines Objektes ändert, und nicht bei jedem Update eines Objektes.
Mögliche Events:
client_created
client_updated
(wird auch beim Löschen gefeuert)property_created
property_updated
(wird auch beim Löschen gefeuert)task_created
task_updated
task_deleted
client_property_created
client_property_updated
client_property_deleted
project_created
project_updated
document_created
document_updated
document_deleted
saved_query_created
saved_query_updated
saved_query_deleted
Hook erstellen
POST
https://api.propstack.de/v1/hooks
Query Parameters
target_url
string
Die URL, die aufgerufen soll, wenn der Hook ausgelöst wird
event
string
Das Ereignis, worauf man hören möchte. Siehe oben für mögliche Werte
{
"id": 123
}
Hooks aufrufen
GET
https://api.propstack.de/v1/hooks
{
"hooks": [
{
"id": 10,
"event": "CLIENT_CREATED",
"target_url": "https://propstack-immobilien.de/ps-hook"
}
]
}
Hook löschen
DELETE
https://api.propstack.de/v1/hooks/:id
{
"ok": true
}
Verifying Webhooks
Verifying webhooks is crucial to ensure the authenticity of the incoming requests and confirm that the data originates from Propstack. To enhance security, we have implemented HMAC (Hash-based Message Authentication Code) verification. This allows developers to confirm that requests come from a genuine source.
When creating a new webhook in the Web UI, there is a field called "Secret Key". Adding a secret key is optional. If it's not set, then no signature will be sent with the webhook. If you do add a secret key, we use this to generate a signature and pass it as a header called X-Propstack-Signature
.
Here's a simple JavaScript example showcasing how to verify the HMAC signature from your end:
const crypto = require('crypto');
function verifySignature(requestBody, signature, secret) {
const hash = crypto
.createHmac('sha256', secret)
.update(requestBody, 'utf8')
.digest('hex');
return hash === signature;
}
This function generates a hash using the request body and a shared secret, then compares it to the signature provided to validate the request.
Verifying HMAC Signature in PHP (WordPress)
For WordPress developers, verifying the HMAC signature can also be done using PHP as shown below:
function verify_signature($requestBody, $signature, $secret) {
$hash = hash_hmac('sha256', $requestBody, $secret);
return hash_equals($hash, $signature);
}
// Usage example within a WordPress context
$requestBody = file_get_contents('php://input');
$providedSignature = $_SERVER['HTTP_X_PROPSTACK_SIGNATURE'];
$secret = 'your_secret_key';
if (verify_signature($requestBody, $providedSignature, $secret)) {
// The request is verified
} else {
// The request could not be verified
}
This PHP function computes an HMAC hash of the request body using the shared secret and compares it to the incoming signature to ensure authenticity.
Last updated