Answers.Body: <p>Well here's an alternate way to try which returns the total result if you have no idea how much entries does the returned result will contain :</p>
  
  <pre><code>$count = civicrm_api('Membership', 'getcount', $params);
  
  $params = array(
    'version' =&gt; 3,
    'sequential' =&gt; 1,
    'membership_type' =&gt; 1,
    'options' =&gt; array(
      'limit' =&gt; $count,
    ),
  );
  
  $result = civicrm_api('Membership', 'get', $params);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-14T06:46:18.247Z
Answers.Text: This is a nice solution
Answers.UserDisplayName: Owen Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-24T14:56:50.167Z
Answers.Text: Nice! Just used this.
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-14T06:17:12.250Z
Answers.LastActivityDate: 2015-07-14T06:17:12.250Z
Answers.UserDisplayName: jitendra - fuzion
Answers.Body: <p>Adding options.limit to 0 returns the total result for the api which I feel is the best way to get more than 25 contacts :)</p>
  
  <pre><code>$params = array(
    'version' =&gt; 3,
    'sequential' =&gt; 1,
    'membership_type' =&gt; 1,
    'options' =&gt; array(
      'limit' =&gt; 0,
    ),
  );
  </code></pre>
  
  <p>$result = civicrm_api('Membership', 'get', $params);</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-31T05:34:47.997Z
Answers.Text: My only concern with this is when you have say 100,000 contacts you need to be able to parse hen in smaller chunks so as to not overwhelm your server.  Thought for things like meme ship types where you likely have less than 100 this is very useful
Answers.UserDisplayName: Owen Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-31T05:21:28.683Z
Answers.LastActivityDate: 2015-07-31T05:21:28.683Z
Answers.UserDisplayName: jitendra - fuzion
Answers.Body: <p>To return more than 25 results you need to <strong>add options.limit to your api call</strong>:</p>
  
  <pre><code>$params = array(
    'version' =&gt; 3,
    'sequential' =&gt; 1,
    'membership_type' =&gt; 1,
      'options' =&gt; array(
      'limit' =&gt; 100,
     ),
  );
  $result = civicrm_api('Membership', 'get', $params);
  </code></pre>
  
  <hr>
  
  <p>For the second part, we want to be able to retrieve say 5,000 records. We can't really set rowCount to 5,000 because depending on the size of data, we run the risk of timing out.</p>
  
  <p>The solution here is to page the results using a parameter 'options.offset':</p>
  
  <pre><code>$params = array(
    'version' =&gt; 3,
    'sequential' =&gt; 1,
    'membership_type' =&gt; 1,
    'options' =&gt; array(
      'limit' =&gt; 100,
      'offset' =&gt; 100 // offset value is equal to the number of results to skip
    ),
  );
  </code></pre>
  
  <p>For this to work, we decide on what our ideal page size is let's say 100. We set options.limit to 100, and then we increment offset by our page size (100) on each call, until we no longer get results.</p>
  
  <p>How do we know when we're done? Check the value of count in the returned result. When the returned count is less than the page size, stop.</p>
  
  <pre><code>  $memberships = array();
    // Initialise our pagesize and offset
    $page_size = 100;
    $offset = 0;
    // Start out loop
    do {
      // Call the api
      $results = civicrm_api(
        'Membership',
        'get',
        array(
          'version'         =&gt; 3,
          'sequential'      =&gt; 1,
          'membership_type' =&gt; $membership_type,
          'options'         =&gt; array(
            'limit'  =&gt; $page_size,
            'offset' =&gt; $offset
          )
        )
      );
  
      // do something with the results if we didn't error
      if ($results['is_error'] == 0) {
        foreach ($results['values'] as $value) {
          $memberships[] = $value;
        }
      }
  
      // Increment the offset by the page size
      $offset = $offset + $page_size;
  
    } while ($results['count'] &gt;= $page_size); // Check if we still need to fetch results
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-03T08:19:07.763Z
Answers.Text: I've used rowCount myself, but is there any difference between that and limit?
Answers.UserDisplayName: DaveFF
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-03T08:55:12.467Z
Answers.Text: @DaveFF they both work, but options.limit appears to be the preferred parameter. I get feeling rowCount will be deprecated in a future api update.
Answers.UserDisplayName: Owen Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-02T01:16:53.933Z
Answers.LastActivityDate: 2015-06-02T01:33:17.023Z
Answers.LastEditDate: 2015-06-02T01:33:17.023Z
Answers.UserDisplayName: Owen Kelly
Body: <p>I'm making a normal api call such as:</p>
  
  <pre><code>$params = array(
    'version' =&gt; 3,
    'sequential' =&gt; 1,
    'membership_type' =&gt; 1
  );
  $result = civicrm_api('Membership', 'get', $params);
  </code></pre>
  
  <p>But I only get 25 results back.</p>
  
  <p>How do I get more than that, and how do I ensure I can retrieve all results, if say there was 5,000?</p>
  
Tags: <api><developer>
Title: How do I get more than 25 records from the API?
ThreadText: # How do I get more than 25 records from the API?
  
  (Asked by: username_0 on 2015-06-02)
  
  I'm making a normal api call such as:
  
  ```
  $params = array(
    'version' => 3,
    'sequential' => 1,
    'membership_type' => 1
  );
  $result = civicrm_api('Membership', 'get', $params);
  
  ```
  
  But I only get 25 results back.
  
  How do I get more than that, and how do I ensure I can retrieve all results, if say there was 5,000?
  
  **Tags:** api, developer
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2015-06-02. Score: 16 | Accepted answer
  
  To return more than 25 results you need to **add options.limit to your api call**:
  
  ```
  $params = array(
    'version' => 3,
    'sequential' => 1,
    'membership_type' => 1,
      'options' => array(
      'limit' => 100,
     ),
  );
  $result = civicrm_api('Membership', 'get', $params);
  
  ```
  
  ---
  
  For the second part, we want to be able to retrieve say 5,000 records. We can't really set rowCount to 5,000 because depending on the size of data, we run the risk of timing out.
  
  The solution here is to page the results using a parameter 'options.offset':
  
  ```
  $params = array(
    'version' => 3,
    'sequential' => 1,
    'membership_type' => 1,
    'options' => array(
      'limit' => 100,
      'offset' => 100 // offset value is equal to the number of results to skip
    ),
  );
  
  ```
  
  For this to work, we decide on what our ideal page size is let's say 100. We set options.limit to 100, and then we increment offset by our page size (100) on each call, until we no longer get results.
  
  How do we know when we're done? Check the value of count in the returned result. When the returned count is less than the page size, stop.
  
  ```
    $memberships = array();
    // Initialise our pagesize and offset
    $page_size = 100;
    $offset = 0;
    // Start out loop
    do {
      // Call the api
      $results = civicrm_api(
        'Membership',
        'get',
        array(
          'version'         => 3,
          'sequential'      => 1,
          'membership_type' => $membership_type,
          'options'         => array(
            'limit'  => $page_size,
            'offset' => $offset
          )
        )
      );
  
      // do something with the results if we didn't error
      if ($results['is_error'] == 0) {
        foreach ($results['values'] as $value) {
          $memberships[] = $value;
        }
      }
  
      // Increment the offset by the page size
      $offset = $offset + $page_size;
  
    } while ($results['count'] >= $page_size); // Check if we still need to fetch results
  
  ```
  
  > **Comments:**
  > **username_3**: I've used rowCount myself, but is there any difference between that and limit?  
  > **username_0**: @username_3 they both work, but options.limit appears to be the preferred parameter. I get feeling rowCount will be deprecated in a future api update.  
  
  ---
  
  ### Answer by username_1 on 2015-07-14. Score: 8
  
  Well here's an alternate way to try which returns the total result if you have no idea how much entries does the returned result will contain :
  
  ```
  $count = civicrm_api('Membership', 'getcount', $params);
  
  $params = array(
    'version' => 3,
    'sequential' => 1,
    'membership_type' => 1,
    'options' => array(
      'limit' => $count,
    ),
  );
  
  $result = civicrm_api('Membership', 'get', $params);
  
  ```
  
  > **Comments:**
  > **username_0**: This is a nice solution  
  > **username_2**: Nice! Just used this.  
  
  ---
  
  ### Answer by username_1 on 2015-07-31. Score: 6
  
  Adding options.limit to 0 returns the total result for the api which I feel is the best way to get more than 25 contacts :)
  
  ```
  $params = array(
    'version' => 3,
    'sequential' => 1,
    'membership_type' => 1,
    'options' => array(
      'limit' => 0,
    ),
  );
  
  ```
  
  $result = civicrm\_api('Membership', 'get', $params);
  
  > **Comments:**
  > **username_0**: My only concern with this is when you have say 100,000 contacts you need to be able to parse hen in smaller chunks so as to not overwhelm your server.  Thought for things like meme ship types where you likely have less than 100 this is very useful  
  
  ---
  
  