Skip to main content
Solved

Run a webhooks when a button is push


Forum|alt.badge.img+4

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 !

Best answer by Sho

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".

View original
Did this topic help you find an answer to your question?

5 replies

Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • Answer
  • June 14, 2023

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".


Forum|alt.badge.img+18

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.


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • June 14, 2023
Stephen_Orr1 wrote:

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.


Forum|alt.badge.img+4
  • Author
  • Inspiring
  • 5 replies
  • June 14, 2023
Sho wrote:

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".


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


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • June 14, 2023

Wow, seems like an AWS problem😂


Reply