In this article, you'll find:
What 'webhooks' are and what they can be used for
Webhooks allow you to seamlessly pass information from Rise.ai to other applications when an event occurs. This automatic data transfer ensures that relevant information is instantly shared without manual intervention.
By using webhooks, you can sync data from Rise.ai into third-party systems, ensure it is up-to-date, and simplify the connection between Rise.ai and the other tools and services you use.
The specific events Rise uses
Gift Card Created Notifies your system when a gift card is created.
Gift Card updated: Notifies your system when a gift card expiration date or balance is modified.
Gift card disable: Notifies when a gift card has been disabled.
Gift card Balance Adjusted: Notifies when a transaction on the gift card, including customer usage or balance changes. (triggered also by wallet transactions).
Store credit issued: Notifies when store credit is issued to a customer.
Store credit balance expired: Notifies your system when store credit has expired.
Please note that only one event of each type can be created.
For detailed information about the data each webhook provides, please refer to our developer docs.
How to configure and create webhooks -
Within your dashboard enter the Integration tab → Developer tools → Create Webhook:
After clicking on Create webhook, you can select the specific event you want to track and insert the callback URL and then click Create.
After creating the webhook, you can test it by clicking Test webhook.
How to Process Webhook Payloads
When working with Rise.ai webhooks, the payload (body) is sent as a JWT (JSON Web Token) encoded in Base64 format and signed with our public key, To process the payload:
Decode the payload into a UTF-8 string to make it readable.
(Optional): Verify the JWT signature against the Public Key (developer docs).
Parse the decoded payload into a JSON object.
Here is a simple example, in JavaScript:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.text());
const base64UrlDecode = str => {
return Buffer.from(str, 'base64').toString('utf8');
};
const parseJwt = token => {
try {
if (!token) {
throw new Error('Token is undefined');
}
const [header, payload, signature] = token.split('.');
if (!payload) {
throw new Error('Invalid token');
}
const decodedPayload = base64UrlDecode(payload);
console.log('Decoded payload as string:', decodedPayload);
const parsedPayload = JSON.parse(decodedPayload);
if (parsedPayload.data && typeof parsedPayload.data === 'string') {
parsedPayload.data = JSON.parse(parsedPayload.data);
}
return parsedPayload;
} catch (error) {
console.error('Error decoding JWT:', error.message);
return null;
}
};
const handleWebhook = bodyAsJwt => {
if (!bodyAsJwt) {
throw new Error('No JWT provided in request body');
}
const payload = parseJwt(bodyAsJwt);
if (!payload) {
throw new Error('Failed to decode JWT payload');
}
console.log('Decoded payload:', payload.data);
return payload.data.data;
};
const logRequestBody = (req, res, next) => {
console.log('Incoming request Body:', req.body);
next();
};
app.use('/giftcard', logRequestBody);
app.post('/giftcard', async (req, res) => {
handleWebhook(req.body);
});
app.listen(3000, () => {
console.log('Server up');
});
Have more questions or any product feedback?
Feel free to contact us at info@rise.ai or in the chat box.