Help

Script triggering webhook and recordID

1092 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Gill
4 - Data Explorer
4 - Data Explorer

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: 

"https://hook.eu2.make.com/myhook?ID=" & RECORD_ID()
But it also opens a new tab, which is unacceptable for my use case.

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);
  }
}

 

 

4 Replies 4

Check out my thread here on how to instantly trigger a webhook in Make from Airtable.

Hope this helps!

— ScottWorld, Expert Airtable Consultant 

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:
Screenshot 2024-09-12 at 9.47.23 AM.png

And you'd set it up like so by clicking the blue + icon and then selecting the record ID!

Screenshot 2024-09-12 at 9.47.34 AM.png

Gill
4 - Data Explorer
4 - Data Explorer

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.

Gill_0-1726127171933.png

Gill_1-1726127414136.png

 

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);
  });