Sep 11, 2024 08:40 AM - edited Sep 11, 2024 08:56 AM
Hello,
I need to trigger a webhook to Make.com, but I need to avoid the confirm tab being opened. Therefore, I cannot simply use button + webhook and I probably need to use a script. And this is the part I cannot do by myself.
So here is the situation - I have a button as one column and what I need to achieve is to send a webhook with recordID to Make. In the interface, I have a "record view", where the button is for each record. The button works fine with this:
So I tried three scripts, but none of them worked. Some of them want to pick an item, that is probably not the right solution for my case.
Can someone help, please?
SCRIPT 1
let table = base.getTable("Myšlenky");
let recordId = input.recordId;
let webhookUrl = `https://hook.eu2.make.com/myhook?ID=${recordId}`;
let record = await table.selectRecordAsync(recordId);
if (record) {
let recordData = {
id: record.id,
};
await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(recordData)
});
}
SCRIPT 2
let table = base.getTable("Myšlenky");
let record = await input.recordAsync("Select a record to use", table);
let url = `https://hook.eu2.make.com/myhook?ID=${record.id}`;
SCRIPT 3
let tableId = cursor.activeTableId
let table = base.getTable("Myšlenky")
let record = await input.recordAsync("Pick a record", table)
let url = 'https://hook.eu2.make.com/myhook?ID=' + record.id
console.log(url)
await fetchData(url)
async function fetchData(url) {
try {
const response = await remoteFetchAsync(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json(); // Assuming the response is JSON
console.log(data);
} catch (error) {
console.error("Could not fetch data:", error);
}
}
Sep 11, 2024 02:20 PM
Check out my thread here on how to instantly trigger a webhook in Make from Airtable.
Hope this helps!
— ScottWorld, Expert Airtable Consultant
Sep 11, 2024 06:50 PM
Try this:
let {recordId} = input.config()
const url = 'https://hook.us1.make.com/d9qrrh73ocitw9r4j1lrbf6obqly9qab?recordId=' + recordId
await fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error('Response error');
}
console.log(response.statusText)
})
.catch((error) => {
console.error('Error:', error);
});
And make sure you've set up your input variables for your script; it should look like this:
And you'd set it up like so by clicking the blue + icon and then selecting the record ID!
Sep 12, 2024 12:50 AM
Thanks for answers @ScottWorld and @TheTimeSavingCo
But it seems I have another issue - where can I set up variables? There is no such field, as you show o your screenshots.
It is only in automation, but I do not want to use automation for this case, because I need to use the "smaller" button, that is in each row in the table.
Sep 12, 2024 01:23 AM - edited Sep 12, 2024 01:24 AM
You're using the script extension so that's slightly different! You won't need to set up variables as that's automatically passed in when you click the button, and so you can try:
let tableId = cursor.activeTableId
let table = base.getTable(tableId)
let record = await input.recordAsync("Pick a record", table)
const url = 'https://hook.us1.make.com/d9qrrh73ocitw9r4j1lrbf6obqly9qab?recordId=' + record.id
await remoteFetchAsync(url)
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
console.log(response.statusText)
})
.catch((error) => {
console.error('There was a problem with the fetch operation:', error);
});