I’m trying to set up a system that reacts when a new Airtable base is created. I know that webhooks require a base ID, which doesn’t work for my use case, and so I’m exploring other options. I’ve reviewed the List Bases API, but it doesn’t provide any details about when a base was created or last updated.
Does anyone know of a workaround or hack to identify newly created bases? I’ve combed through the API documentation but haven’t found a solution. Any suggestions, including code adjustments or filtering strategies, would be much appreciated.
Here’s a sample code snippet that I’m experimenting with:
import requests
def get_recent_bases():
endpoint = 'https://api.airtable.com/v0/meta/bases'
headers = {'Authorization': 'Bearer YOUR_API_KEY'}
result = requests.get(endpoint, headers=headers)
bases_info = result.json()['bases']
# What can I use here to single out new bases?
return bases_info
# Function to handle the new base data
def handle_new_base(base):
pass
Looking forward to your creative solutions. Thanks!
hey there, i’ve run into this issue too. one thing you could try is keeping a local record of the bases you’ve seen before. then when you fetch the list, compare it to your record and flag any new ones. it’s not perfect, but it might work for your needs. good luck!
Having worked extensively with Airtable’s API, I can confirm that retrieving creation and modification timestamps for bases directly isn’t supported. However, I’ve found a workaround that might help you.
Instead of relying on base-level information, you could track the creation time of the first table in each base. When a new base is created, it always comes with at least one table. You can use the List Tables endpoint to get this information.
Here’s how you could modify your code:
import requests
def get_recent_bases():
bases_endpoint = 'https://api.airtable.com/v0/meta/bases'
headers = {'Authorization': 'Bearer YOUR_API_KEY'}
bases = requests.get(bases_endpoint, headers=headers).json()['bases']
for base in bases:
# Use double quotes inside the f-string to avoid conflicts
tables_endpoint = f"https://api.airtable.com/v0/meta/bases/{base['id']}/tables"
tables = requests.get(tables_endpoint, headers=headers).json()['tables']
if tables:
base['created_time'] = tables[0]['createdTime']
return sorted(bases, key=lambda x: x['created_time'], reverse=True)
This approach isn’t perfect, but it’s the closest you can get to identifying new bases without manual tracking. Remember to handle rate limits and pagination for larger accounts.
I’ve encountered a similar challenge and found a practical solution. While Airtable doesn’t provide direct timestamps for base creation, you can implement a polling mechanism. Periodically fetch the list of bases and compare it against a locally stored list. This approach allows you to identify new bases by their absence in your local record.
Here’s a basic implementation:
import requests
import json
from datetime import datetime
def get_and_compare_bases():
endpoint = 'https://api.airtable.com/v0/meta/bases'
headers = {'Authorization': 'Bearer YOUR_API_KEY'}
current_bases = requests.get(endpoint, headers=headers).json()['bases']
try:
with open('known_bases.json', 'r') as f:
known_bases = json.load(f)
except FileNotFoundError:
known_bases = []
new_bases = [base for base in current_bases if base['id'] not in [kb['id'] for kb in known_bases]]
for base in new_bases:
base['detected_time'] = datetime.now().isoformat()
handle_new_base(base)
with open('known_bases.json', 'w') as f:
json.dump(current_bases, f)
return new_bases
This method isn’t real-time but should suffice for most use cases. Remember to run this function at regular intervals.