Call a webhook with record ids
This example shows how to call a third party webhook/automation tool like n8n, make or zapier…
You need to declare the new action with its scope in the
users.js
modelforest/users.js
// forest/users.js
const Liana = require('forest-express-sequelize');
Liana.collection('users', {
actions: [{
name: 'Notify with slack',
type: 'single',
}]
});
Then implement the action as needed in the route route action:
routes/users.js
// routes/users.js
const express = require('express');
const router = express.Router();
const Liana = require('forest-express-sequelize');
const models = require('../models');
const Liana = require('forest-express-sequelize');
const superagent = require('superagent');
router.post('/actions/notify-with-slack', Liana.ensureAuthenticated, async (request, response) => {
const { query, user } = request;
const [userId] = await new RecordsGetter(models.user, user, query).getIdsFromRequest(request);
try {
await superagent.post('https://user.app.nn.cloud/webhook/123456/abcde/').send({ userId });
response.send({ success: 'Called webhook' });
} catch (e) {
return response.status(400).send({ error: `Failure calling webhook: ${e.message}` });
}
});
module.exports = router;