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) »
  • SOLVED: Location API
Pages: [1]

Author Topic: SOLVED: Location API  (Read 1089 times)

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
SOLVED: Location API
August 12, 2010, 03:52:43 am
Hi all,
i am using the location API for a data migration script, and will also use it to synchronize data via the REST interface.
I have the following situation:
- I already have a record in the table civicrm_address for contact_id 276 with primary is 1;
- I am trying to add a location for the same contact with primary is 0;
- my call of the location has the following parameters:
Code: [Select]
$civipar = array(
             "contact_id"       =>  276,
             "is_primary"       =>  0,
             "location_type_id" =>  4,
             "phone"            =>  $locphones,
             "email"            =>  $locemail,
             "street_name"      =>  "Ivarhof,
             "version"          =>  "3.0");
        
         $civires = &civicrm_location_add($civipar);
I get no error from the API, but nothing is added in the database. Anyone aware of this problem or experienced this.....or am I missing the obvious (which is true in most of the cases :-)). I have used the location API before without any problem, but that was in single address situations.
« Last Edit: August 12, 2010, 04:50:06 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Location API
August 12, 2010, 04:24:23 am
I get some result now with this alternative:
Code: [Select]
$locphones = array(array(
    "phone"             =>  "0575-562683",
    "phone_type_id"     =>  "1",
    "location_type_id"  =>  "1"),
    array(
    "phone"             =>  "06-30054096",
    "phone_type_id"     =>  "2",
    "location_type_id"  =>  "1"));

$locemails = array(array(
    "email"             =>  "annet@hommelvanderelst.nl",
    "location_type_id"  =>  "1"));

$address[1]['street_name'] = "Ambachtstraat";
$address[1]['street_number'] = "21";
$address[1]['postal_code'] = "6971 BN";
$address[1]['city'] = "Brummen";
$address[1]['location_type_id'] = "1";
$address[1]['is_primary'] = "1";

$civipar = array(
     "contact_id"       =>  277,
     "phone"            =>  $locphones,
     "email"            =>  $locemails,
     "address"          =>  $address,
     "version"          =>  "3.0");
$civires = &civicrm_location_add($civipar);
print_r($civires);

Street name is still not there, and I need to check that. And next...see if I can add a location, because this is a contact without any location so far.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Location API
August 12, 2010, 04:49:43 am
Ok, the reason why the address was empty in the first call is because 'street_address' has to be added as a separate parameter, and is not created from a combination of street_name, street_number and street_number_suffix.
Also, with the following call I get an additional location, so I am happy after all:

Code: [Select]
$address[1]['street_name'] = "Populierenlaan";
$address[1]['street_number'] = "345";
$address[1]['postal_code'] = "6973 GF";
$address[1]['city'] = "Brummen";
$address[1]['location_type_id'] = "4";
$address[1]['street_address'] = "Populierenlaan 345";
$address[1]['is_primary'] = "1";



$civipar = array(
     "contact_id"       =>  277,
     "address"          =>  $address,
     "version"          =>  "3.0");
$civires = &civicrm_location_add($civipar);
print_r($civires);


Oh, and I did the address array with element 1 because of an earlier post by Eileen about this, I'll check if it is still required.....and if the API caters for processing more than one element in the address array.
« Last Edit: August 12, 2010, 04:52:49 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: SOLVED: Location API
August 12, 2010, 05:55:04 am
The address array does need a hard coded element 1, it does not work if I change the code in the previous post to $address[0].........
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: SOLVED: Location API
August 12, 2010, 03:10:36 pm
Hi Erik - glad to see you were so helpful & gave yourself assistance in resolving this!

There's another thread where there has been some discussion of this & it should probably change - my suspicion is that the reason it works like this is because addresses used to be represented differently to how they are now. I may try to patch up but probably no until I understand why it is hard coded
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: SOLVED: Location API
August 12, 2010, 11:08:13 pm
It is always nice to help myself  ;D
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) »
  • SOLVED: Location API

This forum was archived on 2017-11-26.