@JonathanBowen
Thanks for your suggested solution for this programatic import of CSV to AirTable. I used the code below, which reads the CSV fine however I am getting 422 response from AirTable. I have troubleshooted to the best of my skills, but canāt fix the error. What am I missing?
Please note the ingredient name is a lookup ID, thatās why its in brackets.
import requests
import csv
post_url = 'https://api.airtable.com/v0/appjntXiOLPBmOpKs/WEM%20Dataā'
post_headers = {
'Authorization' : 'Bearer YOUR API KEY',
'Content-Type': 'application/json'
}
f = open('import_data.csv')
csv_f = csv.reader(f)
for row in csv_f:
inventory = row[0]
usage = row[1]
received = row[2]
report_date = row[3]
batch_id = row[4]
lookup_id = row[6]
name = row[7]
data = {
"fields": {
"Name": name,
"Ingredient": [lookup_id],
"Inventory": inventory,
"Usage": usage,
"Receipts": received,
"Report Date": report_date,
"Batch Number": batch_id
}
}
print(post_url)
print(data)
post_airtable_request = requests.post(post_url, headers=post_headers, json=data)
print(post_airtable_request.status_code)
I have been able to validate the post request using these credentials works via Postman, but still having issues. Hereās the first few lines of the CSV file I used:
949.7318,180.3,0,05/21/20,4421b1fa-9bb6-11ea-8f85-8c85904e2678,Agrado Plus,recg1ZpkYgUMXRgZf,Agrado Plus - 2020-05-21
4408,0,0,05/21/20,4421b1fa-9bb6-11ea-8f85-8c85904e2678,EGold Calcium Salt,recvCnq1AXSX7Y6cq,EGold Calcium Salt - 2020-05-21
14354 5441,0,05/21/20,4421b1fa-9bb6-11ea-8f85-8c85904e2678,Smartamine ML,rec36WGlYOrUdEDIu,Smartamine ML - 2020-05-21
Hereās what my local terminal is showing when I run the code using the csv: