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 calls report no error and no return data, huh?
Pages: [1]

Author Topic: API calls report no error and no return data, huh?  (Read 1205 times)

hesco

  • Guest
API calls report no error and no return data, huh?
September 08, 2010, 01:19:33 pm
The docs suggest that every API call to contact_search will return a contact_id,
mine are only returning: {"is_error":0}, which I read to mean there was no error. 
But if that is correct, then where are my results?

Code: [Select]
#!/usr/bin/perl
use strict;
use warnings;

use Data::Dumper;
use CiviCRM::Client::REST;

my $user = 'hesco';
my $pw = 'my_pw';
my $api_key = 'my_api_key';
my $site_key = 'long_cryptic_site_key';

my $civicrm = CiviCRM::Client::REST->new('http://example.com/sites/all/modules/civicrm', $site_key);
my $credentials = $civicrm->login({ 'name' => $user, 'pass' => $pw, 'api_key' => $api_key });

print STDERR 'The result returned by our login attempts reads: ' . Dumper($credentials);

my $src_data = '/home/hesco/CampaignFoundations/Clients/MyClient/first_call_list.csv';
open('SRC','<',$src_data) or die "Unable to open $src_data " . $! . "\n";

my $count;
while(<SRC>){
  my @phones = split ',',$_;
  foreach my $item (@phones){
    $item =~ s/"//g;
    $item =~ s/\s+//g;
  }
  my ($fname,$lname,$phn_hm,$phn_cl,$phn_wk) = @phones;

  my $args = {  'PHPSESSID' => $credentials->{'PHPSESSID'},
                  'api_key' => $api_key,
             'contact_type' => 'Individual',
               'first_name' => $fname,
                'last_name' => $lname,
                'return.id' => 1,
               'return.cid' => 1,
        'return.contact_id' => 1 };

  my $contacts = $civicrm->contact_search($args);

  print STDERR $_, Dumper($args,$contacts);

  $count++;
  if($count > 4){ last; }
}

close(SRC);
exit;

close(RESULT);

1;

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: API calls report no error and no return data, huh?
September 09, 2010, 12:07:51 am
I get that situation when there are no contacts to display, so your contact search does not come up with any data. Looking at your code, what is the function of the return.id, return.cid and return.contact_id in your $args array? I have never used those as parms for contact/search.....? But that might well be my ignorance :-)
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API calls report no error and no return data, huh?
September 09, 2010, 12:28:59 am
I've updated the WIKI to reflect the fact that contact_search is deprecated

http://wiki.civicrm.org/confluence/display/CRMDOC32/Contact+APIs
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

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: API calls report no error and no return data, huh?
September 09, 2010, 12:30:51 am
Thanks Eileen, that makes sense....and I did not think of it alhough I there is a little voice in the back of my mind that says I knew that :-)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API calls report no error and no return data, huh?
September 09, 2010, 12:33:08 am
I just went to take a look for the API standards & struggled to find it using a normal search so here's a handy tip - if you ever want to find it just search the wiki for 'orthogonal'
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

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: API calls report no error and no return data, huh?
September 09, 2010, 12:35:25 am
so hesco, the answer is: use civicrm_contact_get.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API calls report no error and no return data, huh?

This forum was archived on 2017-11-26.