Webhooks
Authentication
import base64
import hashlib
import hmac
from urllib.parse import unquote
# You will provide your assigned Client Solution Engineer with an API key and secret
# they will configure the XCover platform
api_key = "--your-api-key--"
secret = "--your-secret--"
# This is just an example, you would obtain this from your server library
# E.g. a Flask server
# from flask import Flask, request
# app = Flask(__name__)
# @app.post('/my-xcover-webhook')
# def xcover_webhook():
#. request_headers = request.headers
# return do_everything_below()
request_headers = {
'X-Api-Key': '--api-key--',
'Authorization': '--signature--',
'Date': 'Thu, 27 Feb 2025 05:01:47 GMT'
}
# Extract signature from the request headers
auth_header = request_headers.get('Authorization', '')
if not auth_header.startswith('Signature '):
raise ValueError("Invalid Authorization header")
auth_parts = dict(
part.split('=', 1) for part in
auth_header.replace('Signature ', '').split(',')
)
received_signature = unquote(auth_parts.get('signature', '').strip('"'))
# Compute the expected signature
date_header = request_headers.get('Date')
if not date_header:
raise ValueError("Missing Date header")
raw = f"date: {date_header}"
expected_hash = hmac.new(
secret.encode("utf-8"),
raw.encode("utf-8"),
hashlib.sha256
).digest()
expected_signature = base64.b64encode(expected_hash).decode('utf-8')
is_valid = hmac.compare_digest(expected_signature, received_signature)BOOKING_CREATED
BOOKING_UPDATED
BOOKING_CANCELLED
RENEWAL_CREATED
RENEWAL_NOTIFICATION
RENEWAL_DUE
RENEWAL_EXPIRED
Last updated