pulling records with python

Viewed 19

Having some trouble with this. I know that I have to use the offset value to pull more than 100 records, here is what I currently have:

AIRTABLE_BASE_ID = 'airtablebaseid'
AIRTABLE_API_KEY = 'airtableapikey'
AIRTABLE_TABLE_NAME = 'airtablename'
endpoint = f'https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/{AIRTABLE_TABLE_NAME}?filterByFormula=AND(NOT(%7BSent+to+Payroll%7D+%3D+%22Sent%22)%2CNOT(%7BSent+to+Payroll%7D+%3D+%22Skipped%22))'

def get_airtable():
    headers = {
        "Authorization": f"Bearer {AIRTABLE_API_KEY}"
    }

    response = requests.get(endpoint,  headers=headers)
    return response

recordList = []
recordIDs = []
recordTimeStamp = []

response = get_airtable()
data = response.json()
for record in data['records']:
    recordList.append(record['fields'])
    recordIDs.append(record['id'])
    recordTimeStamp.append(record['createdTime'])
    print(record)
1 Answers

Airtable can't give you more than 100 records per request, it works, as you said it, with pagination and offset.

The first request you made without offset parameter will return you a payload with a offset field set to n, you have to pass that offset to your next request to get the n next records, and so on...

response = get_airtable()
data = response.json()
OFFSET = data['offset'] #not sur if "offset" is at root of the response

endpoint = f'https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/{AIRTABLE_TABLE_NAME}?offset={OFFSET}&filterByFormula=AND(NOT(%7BSent+to+Payroll%7D+%3D+%22Sent%22)%2CNOT(%7BSent+to+Payroll%7D+%3D+%22Skipped%22))'
Related