Closed s2t2 closed 10 years ago
i think by default it only returns 20, try using cases(:count => 100)
thanks @wedy, that does return 100 results, but still not all of the available results, and it appears 100 is the largest value that :count
will accept.
Desk.cases(:count => 99).results.map{|r| r.case}.count
=> 99
Desk.cases(:count => 100).results.map{|r| r.case}.count
=> 100
Desk.cases(:count => 101).results.map{|r| r.case}.count
=> 100
Try adding :page as an options, like Desk.cases(:count => 25, :page => 2)
. I think Desk is limiting the results to 100, so you'll need to go to the next page to get anything beyond that.
thanks @chriswarren. based on your feedback, and in case this is helpful to anyone else in the future, here's one way to loop through all cases:
(1..5000).to_a.each do |page_counter|
page_case_results = Desk.cases(:count => 100, :page => page_counter).results
page_case_results.each do |case_result|
c = case_result.case
# do some stuff
end
end
... where 5000 is just some arbitrary large number to serve as a proxy for the number of total pages.
this definitely does the job, although i've run into a separate rate limit error twice now...
GET https://mysubdomain.desk.com/api/v1/cases.json?count=100&page=274: 400: rate_limit_exceeded
i guess i'll just figure out a way around it.
for googlers, here's one way to get around the rate-limiting error:
(1..5000).to_a.each do |page_counter|
page_case_results = Desk.cases(:count => 100, :page => page_counter).results
if page_case_results.count > 0
page_case_results.each do |case_result|
c = case_result.case
# do some stuff
end
else
raise "End of File - #{page_counter - 1} pages"
end
end
The following code only returns the first 20 cases.
Is this a pagination issue? Should I be using different code? I'd appreciate any instructions on how to loop through all existing cases. Thanks!