How to list more than 10 items when listing information via API?

Modified on: Fri, 23 Mar, 2018 at 1:27 AM

This article also answers:

  • What's the maximum number of items that can be listed using the list APIs?
  • Can I get a sample code showing how to use the offset parameter with the list APIs?
----------------------------------------------------------------------------------------------------
By default, our List APIs will return a set of 10 items for Subscriptions, Plans, Addons etc even if you have more data in your account.

If you would like to increase/define the limit, the 'limit' parameter has to be passed along with the API call.


Sample API call :

curl  https://{site}.chargebee.com/api/v2/addons \
     -G  \
     -u {site_api_key}: \
     --data-urlencode limit="15" \
     --data-urlencode type[is]="on_off" \
     --data-urlencode status[is]="active"


The maximum number of items that can be listed is 100 and to retrieve beyond that, you can use the “offset” parameter to fetch the next set of resources. The value used for this parameter must be the value returned for next_offset parameter in the previous API call.


Below is a sample code that will loop through all your subscriptions till the offset is empty.


do {
  $all = ChargeBee_Subscription::all(array(
  "limit" => 100,
  "offset" => $offset
  ));
  $offset=$all->nextOffset();
  foreach($all as $entry){
  $subscription = $entry->subscription();
  echo $subscription->status . "<br />";
/*
Sleep between API calls.
ChargeBee will block your request if it crosses a
threshold of 100 req/min
*/
  sleep(1);
  }
} while($offset);

    

 Here’s our API documentation if you'd like to know more about our APIs and the input parameters. 

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.
×