First create a webhook from Strapi:
Then create a custom api in particular content type directory.
In /api/content-type/routes/content-type.js file:
{
method: 'POST',
path: '/your-api-name',
handler: 'api::region.region.executeExternalApi',
}
and add the function inside /api/content-type/controllers/content-type.js file:
executeExternalApi(): async (ctx) => {
let request = ctx.request.body;
let data = request.entry;
let header = ctx.request.header;
...write your logic here
}
This function will be triggered whenever any record is Published from any of the content type.
If you want your logic to be executed for particular model you can apply a condition logic using ctx.request.body.model === ‘contentType-name’.
Hope this information will be clear to you.
