Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Python API code not working

Topic Labels: Automations
361 1
Showing results for 
Search instead for 
Did you mean: 

I have to upload a file to Airtable. I don’t quite understand the documentation for file upload. I have this code that is in python that should upload a file to airtable via a link but it gives me a 422 error. How can I fix this?

ATBASEID = "****************************"

AIRTABLE_API_KEY = "*************************"
ENDPOINT = "" + \
HEADERS2 = {"Authorization": f"Bearer {AIRTABLE_API_KEY}", "Content-Type": "application/json"}

data2 = [
        "id": "attqyuWADmKW9DgDG",
        "size": 26317,
        "url": "",
        "type": "image/jpeg",
        "filename": "33823_3_xl.jpg",
        "thumbnails": {
            "small": {
                 "url": "",
                 "width": 54,
                 "height": 36
            "large": {
                 "url": "",
                 "width": 197,
                 "height": 131
r_1 = requests.patch(ENDPOINT, json=data2, headers=HEADERS2)

All help is greatly appreciated.

1 Reply 1

Hi @Gabriel_Ferguson - I’ve got a similar script that uploads an attachment to Airtable based on a URL. The key part of the script is:

data = {
  "fields": {
    "Print Preview": [
        "url": image_url
# print(data)
response = requests.patch(api_url, headers=headers, json=data)

So you only need to pass the URL to the API, not the size, type, filename and so on. All of these attributes will be returned if you GET data from the API, but they aren’t needed to POST data.

Note that in my script Print Preview is an attachment field and you pass an array of objects, each object containing the single attribute “url”