error in call to airtable
# 🤝help
b
I am creating a bot where the user enters his email, then enters the area where he wants to go to eat and finally chooses a restaurant to eat (the area and the restaurants are in a knowledge base), then those three data are saved each one in a variable and are stored to later be sent to airtable, this is my code that is in the flow as a node (execute code): const axios = require('axios'); const AIRTABLE_API_KEY = +++++++++++++++++++++++++++++++++ const BASE_ID = 'appNzOV3AL3L2fDdS'; const TABLE_NAME = 'influencers'; const email = @workflow.email; const zona = @workflow.zona; const guardar_restaurant = @workflow.guardar_restaurant; const airtableURL = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME}`; const headers = { 'Authorization':
Bearer ${AIRTABLE_API_KEY}
, 'Content-Type': 'application/json' }; const data = { "fields": { "email": email, "zona": zona, "guardar_restaurant": guardar_restaurant } }; axios.post(airtableURL, data, { headers }) .then(response => { console.log('Datos guardados en Airtable:', response.data); }) .catch(error => { console.error('Error al guardar datos en Airtable:', error); }); (the airtable is correctly configured) and I get this error in the botpress console : Execute code "Post data to Airtable using Axios and API key" Error executing action "inline-card:Post data to Airtable using Axios and API key.js" in flow:Main:node:guardar_restaurant Entering workflow (flow:Error) [node:On_Error] from (flow:Main) [node:guardar_restaurant] how can i fix it?
q
You can remove this part: const axios = require('axios');
and make sure you change your AIRTABLE_API_KEY after showing it here 💡
b
This is how the final code looks but it still doesn't work. const AIRTABLE_API_KEY = '* ** **'; const BASE_ID = 'appNzOV3AL3L2fDdS'; const TABLE_NAME = 'influencers'; const email = @workflow.email; const zona = @workflow.zona; const guardar_restaurant = @workflow.guardar_restaurant; const airtableURL = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME}`; const headers = { 'Authorization':
Bearer ${AIRTABLE_API_KEY}
, 'Content-Type': 'application/json' }; const data = { "fields": { "email": email, "zona": zona, "guardar_restaurant" : guardar_restaurant } }; axios.post(airtableURL, data, { headers }) .then(response => { console.log('Datos guardados en Airtable:', response.data); }) .catch(error => { console.error('Error al guardar datos en Airtable:', error); });
@quick-musician-29561 hi can u help me please?
q
Yes, I can try it also 🛠️
in your code, change these to be without @ symbol: const email = @workflow.email; const zona = @workflow.zona; const guardar_restaurant = @workflow.guardar_restaurant; like that: const email = workflow.email; const zona = workflow.zona; const guardar_restaurant = workflow.guardar_restaurant;
Instead of using the Table Name, it's recommended to use the Table ID. If you change the table name for any reason, you'll also have to update the code, but the table ID still remains the same. So, double-check that you have the correct table name.
Still, the biggest reason might be that API Keys won't work anymore; they stopped it a few months ago, and you have to start using new authentication methods. I use Airtable only with Make.com (because I need Make.com for other stuff too), and it has been the way I recommend to bot builders because. In my opinion, it's easier and faster to start using Airtable with Make.com than without it. They have a very generous free tier, and if you need more, their paid options are also cheaper than competitors like Zapier. Have you tried that?
Using Airtable without Make.com, if your API key doesn't work, you can try with Personal Access Token https://airtable.com/create/tokens/new
after changing it to use Personal Access Token (or if your API key still works), correct this part
Copy code
js
const headers = {
  'Authorization': Bearer ${AIRTABLE_API_KEY},
  'Content-Type': 'application/json'
};
it needs to use backticks (`) so you can use variables there ${}
Copy code
js
const headers = {
  'Authorization': `Bearer ${AIRTABLE_API_KEY}`,
  'Content-Type': 'application/json'
};
same here
Copy code
js
const airtableURL = https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME};
add backticks to the beginning and the end of the variable, like this
Copy code
js
const airtableURL = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME}`;
One last change to your code: Botpress Execute Code cards are asynchronous, so add 'await' before the axios.post to make sure it waits for the response.
Copy code
js
const response = await axios.post(airtableURL, data, { headers });
After making all the necessary changes, try your bot https://cdn.discordapp.com/attachments/1230966467206316062/1231850660123770880/Screenshot_from_2024-04-22_09-06-26.png?ex=66387554&is=66260054&hm=ff09640f6eeaaa0e7ff12bab3ef48ffabfde9473b673b4bbadee5f9207d2b324&
The code I used in Execute code card
Copy code
js
const AIRTABLE_PAT= env.AIRTABLE_PAT;
const BASE_ID = env.BASE_ID;
const TABLE_ID = env.TABLE_ID;

const email = workflow.email;
const zona = workflow.zona;
const guardar_restaurant = workflow.guardar_restaurant;

const airtableURL = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_ID}`;

const headers = {
  'Authorization': `Bearer ${AIRTABLE_PAT}`,
  'Content-Type': 'application/json'
};

const data = {
  "fields": {
    "email": email,
    "zona": zona,
    "guardar_restaurant": guardar_restaurant
  }
};

try {
  const response = await axios.post(airtableURL, data, { headers });
  console.log('Datos guardados en Airtable:', response.data);
} catch (error) {
  console.error('Error al guardar datos en Airtable:', error);
}
https://cdn.discordapp.com/attachments/1230966467206316062/1231851636389974106/Screenshot_from_2024-04-22_09-17-58.png?ex=662752bc&is=6626013c&hm=a35fc0b9a8de49bb2bb2acf4aae2a8b261f6a0a8532d37a88bdda0dcdc31ece3&
b
OMG! thank u sooo much, finally it works! you are a genius 🥰
q
Super! 🦾
p
is there any pricing or anticipated costs of this solutions' deployment?
q
I have used both the free and the cheapest paid versions of those, and they work well. Airtable Free: 100 automation runs $20 a month: 25,000 automation runs Make.com Free: 1,000 operations a month $9 a month: 10,000 operations a month
p
Thanks a lot!
b
Does using airtable as an API call have a cost?
also could you help me with this too? I am making a bot with Instagram integrated , I need that when the user talks to me on Instagram, the bot reads the username and saves it in a variable and then sends it to an airtable, I only need the part that the bot reads the username, I already have the rest.
@quick-musician-29561
q
Hi, sorry I haven't used Instagram integration. I'm sure there are many others who have experience with that
6 Views