CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API only returning 25 records - ***really URGENT***
Pages: [1] 2

Author Topic: API only returning 25 records - ***really URGENT***  (Read 5509 times)

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
API only returning 25 records - ***really URGENT***
October 18, 2011, 12:32:24 pm
I'm using the API to get all the contacts that are of Organization, but it's only returning 25 records (there are 147!). Why is this and how do I get all 147.

Thanks

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API only returning 25 records - ***really URGENT***
October 18, 2011, 12:33:43 pm
Add $params['rowCount'] = 200
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API only returning 25 records - ***really URGENT***
October 18, 2011, 12:47:52 pm
Thanks

Is there a way of makign it so that it'll always return all the results no matter how many there are apart from making rowcount 1000000?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API only returning 25 records - ***really URGENT***
October 18, 2011, 02:56:34 pm
Hi,

A lot of bad things will happen if you try to fetch 100000 of records. I kind of like the visual clue that something (fatal memory exhaustion...) will potentially happen, and that the developer knew it.

This being said, the other (my preferred and the one we should push IMO) is option.limit=250, and I kind of like the idea of introducing an option.nolimit ;)


X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API only returning 25 records - ***really URGENT***
October 18, 2011, 03:02:12 pm
yep - my head just isn't around which api accept option.limit & which don't @ the moment - I don't think contact does - although I think I started the process of having a function to analyse options in an external function on the pledge api
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API only returning 25 records - ***really URGENT***
October 28, 2011, 04:39:28 am
Found an API call that seems to ignore the rowCount

I'm trying to retrieve all the contacts with a specified group_id

$params = array(
   'group_id' => $group_id,
   'api.contact.get' => 1,
   'version' => 3,
   'rowCount' => $maximum_row_count,
);

$result = civicrm_api( 'group_contact','get',$params );

print_r ($result);
printf ('<br><br>');

returns 25 contacts - first part of the print_r is Array ( [is_error] => 0 [version] => 3 [count] => 25
$maximum_row_count = 10000

there are about 50+ results that should be returned.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API only returning 25 records - ***really URGENT***
October 28, 2011, 04:46:13 am
Would be good if you could investigate the underlying BAO call, see if a param is missing/handled differently in that case.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API only returning 25 records - ***really URGENT***
October 28, 2011, 06:46:19 am
Can try, if I can find my way around and when I have time. I'm up against a deadline ATM

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API only returning 25 records - ***really URGENT***
October 28, 2011, 09:07:49 am
Depending on how urgent, quick and easy work around (assuming you are on the latest civi, or backported the api)

create a api/v3/Contact/getCustom.php

function civicrm_api3_contact_getCustom ($param) {
 
  group = (int) $param['group_id'];
  $query = "select .... from civicrm_contact left join civicrm_contact_group... you figure it out group_id=$group"

  $dao = CRM_Core_DAO::executeQuery( $query );
  $r = array ();
  while ($dao->fetch( ) ) {
      $r[] = $dao->toArray();
  }
  return civicrm_api3_create_success ($r,$param,'','',$dao);

}

and you use it with api.contact.getCustom ($yourgroup)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API only returning 25 records - ***really URGENT***
October 31, 2011, 02:23:37 am
Thanks. I'm using another work around ATM, but it's a bit slow. I'll have a look at that later

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API only returning 25 records - ***really URGENT***
December 10, 2011, 02:17:09 am
I've had a poke around the API and it looks like GroupContact.php does not use the rowCount parameter.

The other api code chinks I've looke dat have something like

            $inputParams      = array( );
    $returnProperties = array( );
    $otherVars = array( 'sort', 'offset', 'rowCount' );

    $sort     = null;
    $offset   = 0;
    $rowCount = 25;


in each of them, but GroupContact.php doesn't.

Is there anyone who can confirm what is needed to put into GroupContect.php to sort this out. I could really do with it for Monday

Thanks

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API only returning 25 records
December 10, 2011, 02:26:27 am
Quote from: trevorwood on December 10, 2011, 02:17:09 am
I've had a poke around the API and it looks like GroupContact.php does not use the rowCount parameter.


(haven't tested it)

But the official param to define the limit of how much can be fetched is options.limit=xxx

rowCount is deprecated (might be something to work on to add tests to check it works everywhere in the sprint next week)

Pretty sure that's implemented at the BAO level, shouldn't be too complicated to expose on the API (and patch welcome ;)
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API only returning 25 records - ***really URGENT***
December 10, 2011, 04:00:12 am
sorry - not understanding

so don't use $params['rowCount'] = 200 as suggested in the first reply but something else instead?
$params['options.limit'] =200 ?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API only returning 25 records - ***really URGENT***
December 10, 2011, 12:12:45 pm
Hi,

Long story, but rowCount is an old format used for Contacts, for newer implementations eg for groups we used the options instead (to limit the namespace pollution) and use option.

Use the api explorer
example.org/civicrm/api/explorer?json=1&debug=1&version=3&entity=GroupContact&action=get&option.limit=50

(you should search the api/v3 folder, the code is pretty simple and it should help you
 finding the answers directly).

 
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API only returning 25 records - ***really URGENT***
December 12, 2011, 03:33:22 am
sorry - I must be being thick but I'm totally confused. I can't find any API explorer on my system and I can't find any reference to option.limit either

Could you please give me an example call using the API to return all contacts in a specified group (it would be nicer/more useful if it was a smart group).

Basically I want it to replicate


$params = array(
   'group_id' => $group_id,
   'api.contact.get' => 1,
   'version' => 3,
   'rowCount' => $maximum_row_count,
);


Thanks


Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API only returning 25 records - ***really URGENT***

This forum was archived on 2017-11-26.