Call a webhook with record ids
Please be sure of your agent type and version and pick the right documentation accordingly.
This is the documentation of the forest-express-sequelize
and forest-express-mongoose
Node.js agents that will soon reach end-of-support.
forest-express-sequelize
v9 and forest-express-mongoose
v9 are replaced by @forestadmin/agent
v1.
Please check your agent type and version and read on or switch to the right documentation.
description: >- This example shows how to call a third party webhook/automation tool like n8n, make or zapier…
Call a n8n webhook
You need to declare the new action with its scope in the users.js
model
// 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
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;
PreviousAdd many existing records at the same time (hasMany-belongsTo relationship)NextBulk update records
Last updated
Was this helpful?