-
Notifications
You must be signed in to change notification settings - Fork 301
Retrieving ALL objects of a certain Entity type
Cody Caughlan edited this page May 16, 2014
·
1 revision
When you use the Service#query
method to retrieve objects from an Entity type Intuit will paginate the response and only contain up to 100 records by default. If you really want to retrieve ALL of objects then you'll need to issue a series of queries, only stopping when the result set is empty.
A general pattern to do this is:
# Assumes +service+ is a Service sub-class that has already been configured with the access credentials
drained = false
page = 1
count = 1000
entries = []
while !drained
# passing +nil+ will use the default query for the service
res = service.query(nil, :page => page, :per_page => count)
entries.concat(res.entries)
page = page + 1
drained = true if res.entries.count < count
end
# +entries+ now contains all of your records.
Thank you to markrickert for providing this approach in #113