Events
Working with webhooks
Djamo uses webhooks to notify your application about events related to your API requests so it can react accordingly. For example: we can notify your application when a transaction has been completed.
Working with webhooks is very simple:
- Identify the events that you want to monitor.
- Create webhook endpoints (URLs) on your servers to receive the events payloads.
- Register those URLs on the Djamo API.
- When those events occur, Djamo sends to the URLs a HTTP POST request with a payload.
- Verify that Djamo is indeed sending you the payload by verifiying the header
x-djamo-hmac-sha256inside of the HTTP request. - Respond to the HTTP POST request with an HTTP status code
2xxto indicate that the event was received successfully.
Currently, you can listen to the following events :
| Event | Description |
|---|---|
transactions/started |
Sent when a request for a transaction has been received and queued. |
transactions/completed |
Sent when the transaction has been successfuly executed. |
transactions/failed |
Sent when we failed to execute the transaction for some reason. |
charges/events |
Sent when the status of a charge is updated |
Creating a webhook
POST /v1/webhooks
Parameters
| Parameter | Type | Description |
|---|---|---|
| topic | String | The event that you want to be notified about |
| url | String | The URL of the endpoint that will receive the event payload |
Retrieving details about a webhook
GET /v1/webhooks/:id
Retrieving the list of your webhooks
GET /v1/webhooks
{
"count": 1,
"limit": 15,
"cursor": {
"prev": null,
"next": "bmV4dF9fXzE2Nzg4OTg4MzA2MjA="
},
"data": [
{
"id": "2cdc8ab1-6d50-49cc-ba14-54e4ac7ec231",
"createdAt": "2020-11-24T17:43:15.970Z",
"updatedAt": "2020-11-24T17:43:15.970Z",
"topic": "transaction/started",
"url": "https://myapp.com/webhooks/djamo_transfers"
},
{
"id": "fdfd3ee0-e602-4957-afdd-e3c9e0413af4",
"createdAt": "2020-11-24T17:43:15.970Z",
"updatedAt": "2020-11-24T17:43:15.970Z",
"topic": "transaction/completed",
"url": "https://myapp.com/webhooks/djamo_transfers"
}
]
}
Deleting a webhook
DELETE /v1/webhooks/:id
This will return an empty response with an HTTP code 204.
Verifying payloads from Djamo
Djamo will sign the webhook events it sends to your endpoints by including a signature in each event’s x-djamo-hmac-sha256 HTTP header. This allows you to verify that the events were sent by Djamo, not by a third party. You can verify signatures using the method below.
- Retrieve the
SECRET_KEYsent to you along with yourACCESS_TOKEN. - Compute an HMAC with the SHA256 hash function. Use the
SECRET_KEYas the key, and use the event's payload body string as the message. - Base64-encode the resulting HMAC.
- Compare that signature to the value in the
x-djamo-hmac-sha256header. If they match, the payload is authentic; otherwise, reject the request.
Parsing the payload data
Below is an exemple of such payload body.
{
"data": {
"id": "17750afb-e314-445f-868f-7c75468daac9",
"status": "completed",
"amount": 50,
"msisdn": "+2259800207673",
"description": "Premier test de bulk",
"type": "transfer",
"reference": "89bbf385-da31-4818-9921-542accc77c2d",
"fee": 0.5,
"totalAmount": 50.5,
"failureReason": null,
"batchId": "561958dc-3575-4eef-9e3f-578169b0500d",
"createdAt": "2023-03-23T15:39:42.775Z",
"updatedAt": "2023-03-23T15:40:12.879Z"
},
"topic": "transactions/completed"
}