Jun 13, 2023 01:24 PM
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 :
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 !
Solved! Go to Solution.
Jun 13, 2023 05:59 PM
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".
Jun 13, 2023 05:59 PM
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".
Jun 13, 2023 06:22 PM
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.
Jun 13, 2023 08:11 PM - edited Jun 13, 2023 09:00 PM
Did I need to process an access token for Webhook?
In my environment, it works fine without an access token.
Jun 14, 2023 12:23 AM
In fact, it was Airtable the problem... the server was down....
Jun 14, 2023 12:58 AM
Wow, seems like an AWS problem😂