Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Feb 08, 2024 09:15 PM
Hi,
It's been several months since I've done this, but basically, I'm trying to send an automation from a clicked button in an AT interface to a Make webhook that I've created.
The automation so far was when a button is clicked > run a script. I've been able to successfully pull in a test record id via the "when a button is clicked" stage -- my field is named "rec_id" with the autogenerated formula and that works fine.
FYI--when I hardcode the rec_id in there with the actual value, it works just fine with significantly less code. But with the code below--whenever I get to this step below, it just doesn't work. Can anyone help? Thanks!
let recordID = input.config().rec_id;
// Validate that recordID is not undefined
if (!recordID) {
throw new Error('recordID is undefined. Check the input configuration.');
}
THE WHOLE CODE
// Define the record ID manually for testing purposes
// Define the base URL for the HTTP request to the Make webhook
let url = "https://hook.us1.make.com/mywebhookurl";
// Retrieve the record ID from the input configuration, which is provided by Airtable
let recordID = input.config().rec_id;
// Validate that recordID is not undefined
if (!recordID) {
throw new Error('recordID is undefined. Check the input configuration.');
}
// Access the table where the records are stored
let table = base.getTable('Follow-Ups');
// Retrieve the specific record using the record ID
let record = await table.selectRecordAsync(recordID);
// Extract the values for the fields you want to send to Make
**values for fields i'm extracting
// Construct the payload with the extracted data
let payload = {
**payload I'm sending
};
// Send the payload to the Make webhook via a POST request
let response = await fetch(url, {
method: 'POST',
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json'
}
});
// Check if the request was successful
if (response.ok) {
// If response is successful, log the response or perform other actions
let responseBody = await response.json();
console.log('Success:', responseBody);
} else {
// If the request failed, log the error
console.error('Request failed with status:', response.status);
}
Solved! Go to Solution.
Feb 11, 2024 08:18 AM - edited Feb 11, 2024 08:21 AM
Feb 08, 2024 10:25 PM
Sorry, I don’t know much about scripting, but if you’re interested in a different way of getting the exact same result, I would just use Make’s Airtable Get A Record module to pull in all the Airtable data thar you need.
You can either click on a button in Airtable to trigger the webhook URL directly, or my preferred way of doing this is to use a single select field in Airtable to trigger the Make webhook.
Complete details on my method here: https://air.tableforums.com/t/sending-airtable-data-to-an-external-webhook-such-as-make-com/159
Feb 08, 2024 10:37 PM
It seems like your input config's not set up properly, try setting it up like this instead:
Feb 09, 2024 07:50 PM
Hi, thanks for this. I'll try that out.
Feb 09, 2024 07:50 PM
Feb 09, 2024 11:42 PM
The default response format from a Make webhook isn't JSON, and so attempting to parse the response as JSON using .json()'s causing that error. Try removing line 63 and just console logging 'response' instead. (This assumes you didn't create a webhook response module in your scenario)
The Make scenario runs fine even though your Airtable automation errors though right?
Feb 11, 2024 08:18 AM - edited Feb 11, 2024 08:21 AM