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) »
  • Location API Update does not work
Pages: 1 [2]

Author Topic: Location API Update does not work  (Read 4081 times)

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Location API Update does not work
September 14, 2010, 06:45:48 am
Sorry for the delay on this, I needed time to debug. I've finally tracked this down. The error I was getting was 'Invalid Location Type' but I knew that my location_type_id wasn't invalid. I started debugging api/v2/location.php and realized that the issue was in function civicrm_location_update line 155 where it said:
Code: [Select]
<?php
    
if ( !empty( $locationTypes ) ) {
        
$params['location_type'] = $locationTypes;
    } 
?>

 
This was was passing an array to the next call of civicrm_location_get that looked like this:
Code: [Select]
array ( 0 => 'Delivery')
 
instead of
Code: [Select]
array (6 => 'Delivery')
 
I tested changing that line to:
Code: [Select]
<?php
        $params
['location_type_id'] = $locationTypes; ?>

   

and now it's working.

So the question is, is this a bug? Or am I passing something wrong into the api? The print_r of the arrays I'm passing:

Code: [Select]
Array
(
    [version] => 3.0
    [contact_id] => 6016
    [phone] => Array
        (
            [0] => Array
                (
                    [is_primary] => 0
                    [phone] => 888-888-9999
                    [phone_type_id] => 1
                    [location_type_id] => 6
                )

        )

    [address] => Array
        (
            [1] => Array
                (
                    [location_type_id] => 6
                    [is_primary] => 0
                    [city] => Essex
                    [state_province] => VT
                    [postal_code] => 05452
                    [street_address] => 1 South St
                    [supplemental_address_1] => Apt 1
                    [country_id] => 1228
                    [country] => United States
                )

        )

)

and again I'm then using this call:
Code: [Select]
<?php
$params 
= array(
        
'version' => '3.0',
        
'contact_id' => $cid,
        
'phone' => $phones,
        
'address' => $address,
    );
    
$newLocation =& civicrm_location_update( $params );
?>


xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Location API Update does not work
September 14, 2010, 10:08:37 am
Debug tip: look at the existing unit tests:
tests/phpunit/api/v2/LocationTest.php


Code: [Select]
        $params = array(
                        'phone'                 => $phones,
                        'city'                  => 'Mumbai',
                        'email'                 => $emails,
                        'contact_id'            => $this->_contactID,
                        'location_type_id'      => $location['result']['location_type_id']
                        );

        $locationUpdate =& civicrm_location_update( $params );

is seems that you put the location as the first indice of an array, but it should be directly the param.

Let us know how it goes.

If this is that it mean that you can create several locations in a row (or so it seems) but only modify one. It would be great if you could modify the api so it handles both case (ie. if param['address"] is set, create a new p1 param, and call it recursively.

Good luck

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

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Location API Update does not work

This forum was archived on 2017-11-26.