[beginner help needed]
I’m working on adding new entries to my Airtable database using Python requests library. The official documentation shows this curl example:
curl -X POST https://api.airtable.com/v0/your_base_id/table_name \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"fields": {
"Product": "Laptop",
"Count": "3",
"User_ID": [
"rec123456"
]
}
}'
Here’s my Python attempt:
import requests
BASE_URL = "https://api.airtable.com/v0/your_base_id/table_name"
payload = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
"fields": {
"Product": "smartphone",
"Count": "2",
"User_ID": ["rec789012"]
}
}
response = requests.post(BASE_URL, payload)
print(response.json())
But I keep getting this authentication error:
{'error': {'type': 'AUTHENTICATION_REQUIRED', 'message': 'Authentication required'}}
What’s the correct way to handle the authentication headers in Python requests?