Help

Re: Make.com/Airtable webhook

657 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Schmidt127
4 - Data Explorer
4 - Data Explorer

Hello,

I am looking for some help on an automation I am trying to run.  I am trying to use a make.com webhook with airtable so that when a new record shows up in airtable it sends the webhook to make.com.  I have the script that I am using and the connection and everything works but the webhook does not send the correct bundle of information.  It sends the record ID and then just generic information like 'header 'recipient', etc.  I am a school teacher and not a coder so I have been trying to get Chatgpt to help me with the script and I feel I am really close but don't know the scripting language enough to diagnose the problem.  Any help would be appreciated.

let table = base.getTable("Injury Report Form");
let recordId = input.config().recordId;

// Fetch the specific record
let record = await table.selectRecordAsync(recordId);

// Check if the record is fetched properly
if (record) {
    // Prepare the data to be sent to the webhook
    let data = {
        "recordId": record.id,
        "fields": {}
    };

    // Iterate through each field and add to the data object
    table.fields.forEach(field => {
        data.fields[field.name] = record.getCellValue(field.name);
    });

    // Webhook URL
    let webhookUrl = "https://hook.us1.make.com/mywebhook";

    // Send POST request
    await fetch(webhookUrl, {
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify(data)
    });
}
 
Thank you Mike
16 Replies 16

Thank you for responding.  I don't know exactly as to what you are describing, but I am trying some  of those things.  I know in your screenshot that my bundle did not include the recordID: recSjS...........that was missing.  I am still having trouble getting the webhook to come from airtable and start my automation.  I I have 

1. Webhook

2. Webhook Response

3. Google Docs

4.  The rest of my automation........

5. I think my automation is going to be pretty close to done, but I j ust can't get it to work correctly.

Thank you so much.

Mike

The script i am using now, does bring over all of the fields.  So manually i can get those fields over there when i trigger my automation manually, but I still just can't get the webhook to work.  Thank you.

Mike

Thank you, I got a script from the internet and believe it works for the most part.

const {recordId} = input.config(); // Ensure you have an input variable configured with the name `recordId` and the value "Airtable record ID"
const tableName = "Injury Report Form";

async function sendAllFieldsToWebhook(webhookUrl, recordId, tableName) {
    // Retrieve the table using the specified name
    const table = base.getTable(tableName);

    // Retrieve all fields from the record
    const fieldNames = table.fields.map(fieldObj => fieldObj.name);
    const record = await table.selectRecordAsync(recordId);
    if (!record) {
        throw new Error("Record not found. Should never happen.");
    }

    // Construct the body of the request with field values
    const body = {};
    fieldNames.forEach(name => body[name] = record.getCellValue(name));
    const options = {
        method: "POST",
        body: JSON.stringify(body),
        headers: {"Content-Type": "application/json"}
    };

    // Send the POST request to the webhook URL
    const response = await fetch(webhookUrl, options);
    console.log(response);
}

async function main() {
    await sendAllFieldsToWebhook(webhookUrl, recordId, tableName);
}

await main();
 
Again, I am a teacher of a high school and just got into make a couple of weeks ago and so don't understand some of the things you guys are saying, but I go back to youtube, etc, chatgpt, and try to figure it out.

I did not know that.  I was copy and pasting my new records from previous records.  That was not the underlying problem, but that is good to know.  So when you have a form of 30 fields, what methods do you use to not have to fill in the form over and over again to test?

 

Yes, no data, and the recrodID did not show up?

If you could provide a read-only invite link to a duplicated copy of your base with some example data I could take a look at this for you! https://support.airtable.com/docs/adding-a-base-collaborator#adding-a-base-collaborator-in-airtable

Hello @Schmidt127 
Note → @ScottWorld & @TheTimeSavingCo have already explained most of the things about how to send and handle those webhooks. So I don't want to repeat it. But just try to explain to you the nature of airtable automation.

Before you go to the part of the call make a webhook. These are things you need to know.
First of all, just understand your trigger point is to add a record as you mentioned and @ScottWorld confirmed about that in earlier responses. But for more information, there are multiple ways to add records 1) Manual 2) Via Form submission 3) Via API  4) Import data.

1) Manual → When you add a record as a manual(in Airtable) by default all the fields are blank at the starting point just recId(rec****) is there to access in automation.

2) Via Form → When an Airtable form is submitted it also creates a record on a specific table and it comes with all the data(fields) which is set on the form.

3) Via API → It is the same as form but instead of using the form you can use any third-party tool or directly send using their API Airtable Web API 

4) Import → Just create multiple records based on your source of data.

Now the important thing is using any of the approaches by default whenever the record is created its have recId(rec****).

But,
Here is a thing you need to understand that about automation nature.
No matter which approach you've used when you set trigger automation when the record is added. Then automation is triggered instantly when the record is created. Now when you use the 1) method that time is record is created but all other visible fields do not have data(Maybe you're just filling it, But automation already triggered on add). So in this case you can't pass the other data fields because it is not there to pass alongside your hook.
But this same thing works with all other methods because there is data so you can pass it alongside your request.
If this is the case for you then use condition match when the record is entered to view the approach for trigger automation.
It's a bit long but I hope this helps.
👍