⚠️ APIv2 is legacy
APIv2 is considered legacy and is no longer recommended for new integrations.
We strongly encourage you to use APIv4 for all new integrations and to migrate existing integrations where possible.
Please refer to our latest APIv4 documentation for up-to-date information and integration guidelines:
Click here to view the APIv4 example documentation - your own documentation is at https://[your-instance].langlion.com/api/v4/docs
Webhooks
When building LangLion integrations, you might want your applications to receive events as they occur in LangLion, so that your backend systems can execute actions accordingly.
To enable webhook events, you need to register webhook endpoints. After you register them, LangLion can push real-time event data to your application’s webhook endpoint when events happen on the LangLion Platform.
Using webhook events are particularly useful for listening to asynchronous events (eg. new invoice has been created, time of lesson has been changed, message has been sent to user and so on).
Event structure
1{
2 "event":"invoice.created", // type of event
3 "object":{ // object related to specific event, eg. invoice
4 "id":2413,
5 "userId":1014,
6 "paymentFormId":10,
7 "date":"2023-11-03 00:00:00",
8 "soldAt":"2023-07-19 00:00:00",
9 "paidAt":"2023-07-19 00:00:00",
10 "dayLimit":14,
11 "place":"Warszawa",
12 "statusOffice":2,
13 "statusOfficeName":"paid",
14 "statusPrint":2,
15 "statusPrintName":"paid",
16 "daysOutdated":null,
17 "numberId":3694,
18[...]
19 "description":"Payment",
20 "creatorUserId":2,
21 "deliveredAt":"2023-11-03 00:00:00",
22 "schoolId":4,
23 "connectedId":2268,
24 "createdAt":"2023-11-03 09:58:00",
25 "updatedAt":"2023-11-03 09:58:02",
26 "currencyExchange":null
27 }
28}Supported events
- invoice.created - invoice has been created
- invoice.updated - invoice has been updated
Event delivery failure
When webhook callback fails (HTTP status code different than '200'), there will be a few attempts to deliver a given event to your webhook endpoint for up to 3 days with an exponential back off.
Event signature
Every webhook event is signed before sending it to your endpoints by including a signature in each event’s Webhook-Signature header. This allows you to verify that the received event can be trusted. Webhook-Signature header is the JSON object with the timestamp and the signature included.
Example of Webhook-Signature header
1"{"timestamp":1703792536,"signature":"537c90d454bf56647f3d1a822f784f229088aa83ad88e4dcf0ea5bb9265bb04b"}"Event signature verification
It's a good practice to verify event signatures to confirm that received events are sent from LangLion. Signature verification allows to prevent a replay attack when an attacker intercepts a valid payload and its signature, then re-transmits them. To mitigate such attacks, every includes a timestamp in the Webhook-Signature header. Because this timestamp is part of the signed payload, it’s also verified by the signature, so an attacker can’t change the timestamp without invalidating the signature. If the signature is valid but the timestamp is too old, you can have your application reject the payload.
Example of event signature verification in callback (PHP)
1$payload = @file_get_contents('php://input');
2
3$headers = getallheaders();
4$headerSignature = $headers['Webhook-Signature'];
5
6// parts consist of timestamp and signature
7$parts = json_decode($headerSignature, true);
8$receivedTimestamp = $parts['timestamp'];
9$receivedSignature = $parts['signature'];
10
11// prepare event data in a format ready for signage
12$event = sprintf("%s;%s", $receivedTimestamp, $payload);
13$mySignature = hash_hmac('sha256', $event, 'api client secret');
14
15print($mySignature === $receivedSignature ? "valid signature" : "invalid signature");Register webhook - POST /api/v2/webhook
To receive events related to different objects you need to register webhook related to specific type of objects (eg. invoice) and events (eg. created, updated)
Request
1$ curl --location 'test.langlion.com/api/v2/webhook' \
2--header 'Authorization: Bearer 5470b9d687f47e95bfbc972a7e6a27...' \
3--form 'event="invoice.created"' \
4--form 'callbackUrl="http://yourapp.com/callback"'Response
1{
2 "data": {
3 "webhook": {
4 "id": 10,
5 "event": "invoice.created",
6 "callbackUrl": "http://yourapp.com/callback",
7 "createdAt": "2023-12-28 17:10:19",
8 "updatedAt": "2023-12-28 17:10:19"
9 }
10 }
11}Parameters
Required
- event - what event to notify about - see Supported Events
- callbackUrl - url where event data will be delivered
Optional
No optional parameters.
Delete webhook - DELETE /api/v2/webhook
Request
1$ curl --location --request DELETE 'test.langlion.com/api/v2/webhook?id=10' \
2--header 'Authorization: Bearer 5470b9d687f47e95bfbc972a7e6a273a31f2dadbf98872b5e4e7b0d06de2f24dbaa8cef221adeafb3045745eaf4559f31afa25e79495b75d891847b77f77e8eac8ab14...'Response
1{
2 "data": {
3 "webhook": {
4 "id": 10,
5 "isDeleted": true,
6 "deletedAt": "2023-12-28 20:52:45"
7 }
8 }
9}Parameters
Required
- id - id of webhook
Optional
No optional parameters.
List all webhooks - GET /api/v2/webhooks
Request
1$ curl --location --request GET 'test.langlion.com/api/v2/webhooks' \
2--header 'Authorization: Bearer 5470b9d687f47e95bfbc972a7e6a273a31f2dadbf98872b5e4e7b0d06de2f24dbaa8cef221...'Response
1{
2 "data": {
3 "webhooks": [
4 {
5 "id": 10,
6 "event": "invoice.created",
7 "callbackUrl": "http://langlion.local/cb.php",
8 "createdAt": "2023-12-28 17:10:19",
9 "updatedAt": "2023-12-28 20:52:45"
10 }
11 ]
12 }
13}Parameters
No parameters.