Help

Re: Run a webhooks when a button is push

Solved
Jump to Solution
2944 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Nocode34130
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all,

I try to run this script :

"when a button is clicked in an interface this script is running. It's pointing to another automation triggered by this webhooks to create a new record in a table.

 

 

const URL_AIRTABLE_WEBHOOK = 'https://hooks.airtable.com/workflows/v1/genericWebhook/XXXXXXXXXX/YYYYYYYYYYY/ZZZZZZZZZZZ'

let config = input.config()

let response = await fetch(URL_AIRTABLE_WEBHOOK, {
    method: 'POST',
    body: JSON.stringify({'dossier_record_id':config.dossier_record_id}),
    headers: {
        'Content-Type': 'application/json',
    },
});
console.log(await response.json());

 

 

But It returns :

ERROR

There was an unexpected error while executing your script.

I'm tired and I don't see my error... After all I want is to create a new record in a table when a button is clicked... is there another to do that ?

Thanks !

1 Solution

Accepted Solutions
Sho
11 - Venus
11 - Venus

I think the script is fine.
Is your input.config set up correctly?

And does it need to be a webhook to create a record with a button?
Do you create the record in an external Airtable? Normally a webhook is created with "Create record".

See Solution in Thread

5 Replies 5
Sho
11 - Venus
11 - Venus

I think the script is fine.
Is your input.config set up correctly?

And does it need to be a webhook to create a record with a button?
Do you create the record in an external Airtable? Normally a webhook is created with "Create record".

You're not authenticating the API call. Try this

//schema.bases:write scope required in https://airtable.com/create/tokens
let TOKEN = 'YOUR_PERSONAL_ACCESS_TOKEN'

try {
  let response = await fetch(API_URL, {
    method: 'POST',
    body: JSON.stringify({ dossier_record_id: config.dossier_record_id }),
    headers: {
      'Content-type': 'application/json',
      Authorization: `Bearer ${TOKEN}`,
    },
  });
  console.log(await response.json());
} catch (err) {
  console.log(err);
}

 Also, if you're trying to activate an Airtable automation from an interface button, Airtable has a built in trigger for this.

Did I need to process an access token for Webhook?
In my environment, it works fine without an access token.

Nocode34130
5 - Automation Enthusiast
5 - Automation Enthusiast

In fact, it was Airtable the problem... the server was down....

Sho
11 - Venus
11 - Venus

Wow, seems like an AWS problem😂