Integrating real time Lenme webhook notifications into your server side
Integrating Lenme Webhooks into Your Server
Webhooks provide real-time notifications about events, allowing your server to stay updated as changes occur. Lenme's webhook functionality enables your server to receive these notifications seamlessly. This guide will walk you through the integration process using multiple programming languages such as Python, Java, PHP, and more.
Verification and Data Extraction
The integration process involves verifying and extracting data from the webhook payload and headers. When a webhook notification is received, it includes a JSON payload encoded as a JWT token. This token contains all the necessary event data. Additionally, headers such as X-Lenme-Topic identify the type of event.
To ensure the integrity and authenticity of the received data, the webhook payload is signed using a secret key provided during subscription. This secret key allows your server to decode the JWT token and verify its authenticity. Once verified, the data can be extracted and processed accordingly.
This guide will provide step-by-step instructions on how to handle these tasks, including:
Setting up your server to receive webhook notifications.
Verifying the JWT token using the provided secret key.
Extracting event data from the payload.
Processing the data based on the event type indicated in the headers.
Code examples for verification incoming webhooks
import jsonimport jwtsecret_key ="your-webhook-secret-key-here"defvalidate_lenme_webhook(request_body,headers): body = json.loads(request_body) token = body.get("token") topic = headers.get("X-Lenme-Topic") data = jwt.decode(token, secret_key, algorithms=["HS256"])return data
importorg.json.JSONObject;importio.jsonwebtoken.Jwts;importio.jsonwebtoken.Claims;publicclassValidateLenmeWebhook {privatestaticfinalString SECRET_KEY ="your-webhook-secret-key-here";publicstaticClaimsvalidateLenmeWebhook(String requestBody,Map<String,String> headers) {JSONObject body =newJSONObject(requestBody);String token =body.getString("token");String topic =headers.get("X-Lenme-Topic");Claims data =Jwts.parser().setSigningKey(SECRET_KEY.getBytes()).parseClaimsJws(token).getBody();return data; }}