Christophercorrea / Chris

Hi,
0 stars 0 forks source link

How to link airtable with a google sheet to be able to update date automatically from airtable to google sheet #1

Open Christophercorrea opened 1 month ago

Christophercorrea commented 1 month ago

import requests

Configura la URL de la API de Airtable

base_id = 'TU_BASE_ID' table_name = 'NOMBRE_DE_LA_TABLA' api_key = 'TU_API_KEY' url = f'https://api.airtable.com/v0/{base_id}/{table_name}'

Realiza la solicitud GET a la API de Airtable

headers = { 'Authorization': f'Bearer {api_key}' } response = requests.get(url, headers=headers) data = response.json()

from oauth2client.service_account import ServiceAccountCredentials import gspread

Configura las credenciales de Google Sheets

scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive'] creds = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope) client = gspread.authorize(creds)

Abre la hoja de cálculo

sheet = client.open("Nombre_de_tu_hoja_de_cálculo").sheet1

Actualiza los datos en la hoja de cálculo

for record in data['records']: row = [record['fields']['Campo_1'], record['fields']['Campo_2'], ...] # Ajusta los nombres de los campos según tu Airtable sheet.append_row(row)