Only fetches 99 items.
MikeVaughanG opened this issue · 5 comments
It will only fetch 99 items for me.
I have a 157 on my airtable.
Other than that, I think it works fine.
at = airtable.Airtable('appua4wbLWf65hiXG/', 'my_api_key')
clients = at.get('Clients')
print clients
It fetches only one page of records(that is limited to 100 records). The api call returns an "offset" to fetch the next page. See the forEach implementation in the JS client: https://github.com/Airtable/airtable.js/blob/master/lib/table.js#L73
Is there a way to increase this page limit? I think I might be missing something.
Pardon me, I'm new to this.
Im using this code to return a list of the records on my table, using the 'Name'
field as the keys, and a dict
as a value for each one.
def get_clientlist():
at = airtable.Airtable('appua4wbLWf65hiXG/', 'my_api_key')
clients = at.get('Clients')['records']
client_list = {}
for item in clients:
name = item['fields']['Name']
client_list[name] = item['fields']
return client_list
As @syrnick suggested, you could do something like using offset:
def get_clientlist():
at = airtable.Airtable('appua4wbLWf65hiXG/', 'my_api_key')
client_list = []
clients = at.get('Clients')
offset = clients.get('offset')
client_list.append(clients['records'])
while offset:
clients = at.get('Clients', offset=offset)
offset = client.get('offset')
client_list.append(clients['records'])
return client_list
You could also do everything in a while loop, problem being that offset must be a string with this version.
Thanks a ton, guys. I got it working now.
Sorry for the late reply.
And since this isn't technically an 'issue', I'll close it.
@MikeVaughanG how did you print out client_list
? Using your code above, I added two lines at the bottom:
from airtable.airtable import Airtable
from airtable import airtable
import requests
def get_clientlist():
at = airtable.Airtable('BASE ID', 'API KEY')
client_list = []
clients = at.get('Project%20Tracker')
offset = clients.get('offset')
client_list.append(clients['records'])
while offset:
clients = at.get('Project%20Tracker', offset=offset)
offset = client.get('offset')
client_list.append(clients['records'])
return client_list
a = get_clientlist()
print a
However, I'm getting the following error:
File "airtable_test.py", line 22, in <module>
a = get_clientlist()
File "airtable_test.py", line 17, in get_clientlist
clients = at.get('Project%20Tracker', offset=offset)
File "/usr/local/lib/python2.7/site-packages/airtable/airtable.py", line 76, in get
if offset and check_string(offset):
File "/usr/local/lib/python2.7/site-packages/airtable/airtable.py", line 31, in check_string
raise IsNotString('Expected a string')
airtable.airtable.IsNotString: Expected a string```