Hi guys,
I need an info if Backendless support web-hook on insert or update in a table.
I need a possibility to receive the newly added or newly updated table row in my database table hosted in Backendlless via web-hook so that I could store it in my local db. I would like to create a URL that I will pass to Backendless and on each change in my table this url will be triggered and the changed data will be passed to it so that I will receive it in my application for further processing.
Is there such option in Backendless and how should I use it?
Thank you,
Dimitar
Hi Dimitar
You should create custom event handlers for afterCreate and afterUpdate events
Both event handlers should send an html request to your service with the changed data in the body.
Something like this :
const http = require('http');
function sendChangedDataToMyService(req) {
return new Promise((resolve, reject) => {
var options = {
hostname: 'my_service_host_name',
port: 80,
path: '/updateDBItem',
method: 'POST',
...
};
var req = http.request(options, resolve);
req.on('error', reject);
req.write(req.item); //here we use an item to be changed/created as http request body
req.end();
});
}
Backendless.ServerCode.Persistence.afterCreate('*', sendChangedDataToMyService, true)
Backendless.ServerCode.Persistence.afterUpdate('*', sendChangedDataToMyService, true)
See also: