Script for sending a webhook

Hi Fiberistas,

I’m trying to set up a Fibery automation to send a webhook to a Make.com (aka integromat) webhook url, but don’t really code :-P.

My use-case: every time an entity is updated and meets certain filters, I want to send it via Webhook to Make.com. In the Webhook payload, I’d like it to send the UUID of the entity that has just met the trigger criteria.

Any chance someone can help me out with a sample script?

Any leads would be greatly appreciated!

Best,
Max

2 Likes

Make.com will automatically create a Fibery webhook for you. No scripting required.
Just set up a new scenario in Make, then

  • Create a Fibery “Watch Events” Trigger (you might need to connect it to your Fibery Workspace & OAuth)

  • Create a connection to your Fibery Workspace (if you haven’t already done this in Make).

  • Choose the Fibery DB/entity Type that you want to watch.

Then your Trigger will receive an event every time an entity of that DB/Type is created or changed. It will have all the fields, including Id and Name.

Here is a simple Make.com blueprint I am using to push new Fibery entities into Asana:
Make.com Fibery-Asana blueprint.json

3 Likes

Thanks a bunch @Matt !

Yes, I had done this, and noticed that the Webhook was getting a packet every time the DB in questions was updated.

My issue with this solution - I have a team of ppl constantly creating & updating records in this database, and I only need the automation to fire on a very small fraction of the updates (less than 1%), as shown below, and I’m trying to save Make operations ;-):

Setting up the automation & filters is easy, but I’m a bit slow with the script. @Chr1sG was kind enough to take an initial stab at this here:

for (const entity of args.currentEntities) {
await http.postAsync(‘https://hook.us1.make.com…’, {
body: {
text: entity.id
},
headers: {
‘Content-type’: ‘application/json’
}
});
}

Currently I’m getting this error though: Failed to execute Action “Script”: http is not defined

My goal is to at least send the entity UUID to Make, then I can pull the rest of the data with the search operator and continue syncing with other apps.

Would be really useful to have this code snippet, if anyone is able to help!

Thanks so much :).

Best,
Max

1 Like

You need:

const http = context.getService('http');
3 Likes

It works perfectly :).

Thanks @Matt_Blais & @Chr1sG !

1 Like

So, for future reference, here’s the complete code snippet.

const http = context.getService('http');

for (const entity of args.currentEntities) {
    await http.postAsync('https://hook.us1.make.com/...', {
        body: {
            matchUUID: entity.id,
            name: entity.name
        },
        headers: {
            'Content-type': 'application/json'
        }
    });
}
3 Likes

A last question → as you can see above, I’m happily building out the contents of the webhook with various datapoints from the entity (name, UUID, etc).

Is there a short and easy way to just have the Webhook send ALL the data in args.currentEntities? As opposed to defining each field to be sent by hand?

Thanks again :smile:

Indeed there is - this will pass all the fields in entity:

const fibery = context.getService('fibery')
const http = context.getService('http')
const MAKE_HOOK_URL = 'https://hook.us1.make.com/......'

for (const entity of args.currentEntities) {
    await http.postAsync(MAKE_HOOK_URL, {
        body: entity,
        headers: { 'Content-type': 'application/json' }
    })
}

Note that you may then need to force Make to “Redetermine Data Structure” for the webhook, to pick up all the new fields:

2 Likes

That worked perfectly! Thanks Matt :smile:

Very last question on this topic (i hope :sweat_smile:)…

Is there also a way to send attachment files via webhook?

In our use case, we are sending candidate profiles, it would also be great to send their CV which is generally attached as a pdf to the entities were are sending.

An alternative might be to generate an external link for each file attached to an entity… not sure if this is possible yet?

There are currently no direct script functions for retrieving files, but you can query the entity to get the ‘secret’ of any file(s) in the Files collection field, and then construct urls for downloading them:

const fibery = context.getService('fibery');
const utils = context.getService('utils');

for (const entity of args.currentEntities) {
    
    const entityWithFilesField = await fibery.getEntityById(entity.type, entity.id, ['Files']);

    const files = await fibery.getEntitiesByIds('fibery/file', entityWithFilesField['Files'].map(file => file['id']), ['fibery/secret']);

    for (const file of files) {
        const url = utils.getEntityUrl('api/files', file['fibery/secret']);
        console.log(url);
    }
}
2 Likes

This thread just saved me lots of heartache. Thanks to all who contributed!

3 Likes

It would be really awesome if Fibery team had this example of usage documented in the documentation.

It took a lot of search in the forum to find out if it was possible to trigger a webhook from the Rules inside Fibery.

And after I found out, I couldn’t find an example of doing it.

cc/ @Chr1sG

3 Likes

We are considering adding Send Webhook action, please provide your ideas if any!

2 Likes