Skip to main content
Solved

How to get more than 100 rows using Airtable API in Python using offest?


Forum|alt.badge.img+1

Hello.
I am really new to the Airtable API and for some reason connecting the API this way did not work-

    at = airtable.Airtable('Base_Key', 'Airtable_Key')

But I got it working this way -

get_url = ‘https://api.airtable.com/v0/BASE_ID/TABLE_NAME’
get_headers = {
‘Authorization’: ‘Bearer API_KEY’ }

Response = requests.get(get_url, headers=get_headers)
Response_Table = Response.json()

However, this fetches only the first 100 records and am reading about offset and pagination but I am unable to figure how to incorporate it into this code.

Thank you for the time!

Best answer by Krishangi_Goswa

Krishangi_Goswa wrote:

Update :
I am trying this way -

get_url = 'https://api.airtable.com/v0/appXXXXXXXXXX/TABLE_NAME'
get_headers = {
    'Authorization': 'Bearer keyXXXXXXXXX' ,
    'Offset' : 'itrXXXXXXX/recXXXXXXX'
}

try :
    Response= requests.get(get_url, headers=get_headers})
    Response_Table = Response.json()
    #print(Response_Table)
    
except error as e:
    print(e)

And I get the error :

{'error': {'type': 'INVALID_OFFSET_VALUE', 'message': 'The value of offset ‘itrXXXXXX/recXXXXXX’ is invalid'}}

I would appreciate any leads. Thank you!


After a lot of issues, I found this solution.
Posting it for anyone else facing the same problem.

global offset
offset = '0'
result = []

while True :
    url = "https://api.airtable.com/v0/BASE_ID/TABLE_NAME"
    querystring = {
        "view":"Published View",
        "api_key":"YOUR_KEY",
        "offset": offset}

    try :
        response= requests.get(url, params=querystring)
        response_Table = response.json()
        records = list(response_Table['records'])
        result.append(records)
        #print(records[0]['id'] , len(records))
    
        try : 
            offset = response_Table['offset']
            #print(offset)
            
        except Exception as ex:
            #print(ex , offset)
            break
    
    except error as e:
        print(e)

Thank you!

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+1

Update :
I am trying this way -

get_url = 'https://api.airtable.com/v0/appXXXXXXXXXX/TABLE_NAME'
get_headers = {
    'Authorization': 'Bearer keyXXXXXXXXX' ,
    'Offset' : 'itrXXXXXXX/recXXXXXXX'
}

try :
    Response= requests.get(get_url, headers=get_headers})
    Response_Table = Response.json()
    #print(Response_Table)
    
except error as e:
    print(e)

And I get the error :

{'error': {'type': 'INVALID_OFFSET_VALUE', 'message': 'The value of offset ‘itrXXXXXX/recXXXXXX’ is invalid'}}

I would appreciate any leads. Thank you!


Forum|alt.badge.img+1
Krishangi_Goswa wrote:

Update :
I am trying this way -

get_url = 'https://api.airtable.com/v0/appXXXXXXXXXX/TABLE_NAME'
get_headers = {
    'Authorization': 'Bearer keyXXXXXXXXX' ,
    'Offset' : 'itrXXXXXXX/recXXXXXXX'
}

try :
    Response= requests.get(get_url, headers=get_headers})
    Response_Table = Response.json()
    #print(Response_Table)
    
except error as e:
    print(e)

And I get the error :

{'error': {'type': 'INVALID_OFFSET_VALUE', 'message': 'The value of offset ‘itrXXXXXX/recXXXXXX’ is invalid'}}

I would appreciate any leads. Thank you!


After a lot of issues, I found this solution.
Posting it for anyone else facing the same problem.

global offset
offset = '0'
result = []

while True :
    url = "https://api.airtable.com/v0/BASE_ID/TABLE_NAME"
    querystring = {
        "view":"Published View",
        "api_key":"YOUR_KEY",
        "offset": offset}

    try :
        response= requests.get(url, params=querystring)
        response_Table = response.json()
        records = list(response_Table['records'])
        result.append(records)
        #print(records[0]['id'] , len(records))
    
        try : 
            offset = response_Table['offset']
            #print(offset)
            
        except Exception as ex:
            #print(ex , offset)
            break
    
    except error as e:
        print(e)

Thank you!